How to read 4 numbers at a time, and should such numbers be separated by space only?

1

I made this code but the error on the 2nd line:

In this case I did this function to solve a problem that my teacher passed, to know if a student was approved, disapproved, approved with praise or if he is going to do final proof. Please help me.

def AnalisarSituacao():

   nota1, nota2, nota3, nota4 = float(input()) 

   mediaP= (nota1*1+nota2*2+nota3*3+nota4*4)/10

  if mediaP >=3: 
   if mediaP <7:
    print('prova final')
  if mediaP <3:
    print('reprovado')
  if mediaP >=7:
   if mediaP <9:
    print('aprovado')
  if mediaP >=9:
    print('aprovado com louvor')
    
asked by anonymous 05.11.2017 / 18:24

2 answers

0

Your code can be written like this:

def analisar_situacao(media):
    if media < 3:
        print('Reprovado')
    elif media < 7:
        print('Prova final')
    elif media < 9:
        print('Aprovado')
    else:
        print('Aprovado com louvor')


nota1, nota2, nota3, nota4 = map(float, input().split())

m = (nota1 + nota2 * 2 + nota3 * 3 + nota4 * 4) / 10

analisar_situacao(m)
    
06.11.2017 / 19:14
0

To receive more than one parameter through the input you can use:

    nota1, nota2, nota3, nota4 = input().split(" ")

In this way the console will wait for an entry with 4 values separated by space.

Ex 9.0 6.2 7.3 8.0

Now it is necessary to convert the type (from str to float), in which case you can do it directly in the calculation.

    mediaP= (float(nota1)*1+float(nota2)*2+float(nota3)*3+float(nota4)*4)/10

For the rest of the code, pay attention to the indentation.

pS .: Maybe you can refine this decision tree a little bit.

    
06.11.2017 / 19:03