I couldn’t understand your doubt, because I ran your code here and it all worked out! If the problem is that when the student is approved, the other if block also passes the test by returning "approved" twice is quite simple to solve, just move the recovery note block inside your first Else block getting that way:
`n1 = int(input('Insira a nota da prova 1: '))
n2 = int(input('Insira a nota da prova 2: '))
media = (n1 + n2) / 2
media_rec = media
print ('A média é: ', media)
if media > 5:
print ('Aprovado')
else:
if media < 5:
recuperação = int(input('Nota da recuperação: '))
media_rec = (media + recuperação)/2
print ('A média é: ', media_rec)
if media_rec > 5:
print ('Aprovado')
else:
print ('Reprovado')`
As you can see I have only identented 2° if/Else block within 1° I and removed one of the two instructions "print('failed')
As for the reason of neither the return
, nor the break
nor the return break
function is that they are "methods" (so to speak) specific to other logical structures and functions. The "Return" only works and is valid in a function in your case if you had taken this code and turned it into a function and asked the function to return a print of the student’s state. "Break" is unique to the "while" loop, which in your case is used to approve/fail n students, that is, while there are n students repeat the assignments questions and etc. When there are no more n students (which can be a user input) break that would stop the repetition.
Complementing: the
break
can be used within afor
also.– Paulo Marques
Correct! I forgot to talk about this case, but thanks for the supplement
– Elias Oliveira