I would risk something like:
media = (nota_1 + nota_2)/2
if media <= 4.0:
print('reprovado')
elif media >= 7.0:
print('aprovado')
else:
print('exame')
Now, it’s not enough to know HOW, but yes WHAT this doing, first of all, avoid using accentuation as this can generate many problems by file formatting compatibility, this becomes even more dangerous in interpreted languages (as the case of Python).
Understanding the code: well, I did not put integer, but only the part that you doubt, note that I receive the values of the notes and do the average calculation, Python understands that the variable media
is a float
because she gets float
as a value.
Understanding the conditional ones if
, elif
and else
: they work with value boolean
, that is to say, true or phony, do not compare different values from this, note that in media <= 4.0
the result of this comparison is a boolean
although the data are float
, That’s because the parole is comparing the condition <=
, that is to say: "media
is greater than or equal to 4.0
, true or false?".
Notice that I set up a different structure, because understanding the problem of the table I see that the average being less than or equal to 4.0, the student is failed, if it is between 4.1 and 6.9 he enters the exam, but if it is above 7.0 he is approved.
What is your doubt?
– Luiz Augusto
how do I enter those table values into the program using conditional
– Thanos
Hello @Halan, welcome to Sopt, You need to let us know what your question is, take a look at our [Tour] and [Ask]. - To add information click on [Edit] below the question. = P --- In your code there are 2 things I wouldn’t do, Accentuated variable and convert the
boolean
in theif
forfloat
.– Icaro Martins
Hi, I believe that is accent even, that can not be used, because of the conversion of the compiler itself.
– Philip Developer
@Philipramkeerat Yes, Python accepts Unicode names without any problem.
– Woss
@Andersoncarloswoss I remembered the utf-8 that we can insert
– Philip Developer
Instead of
if float(média <=4.0):
, you should useif float(média) <= 4.0:
, that is, the parenthesis is in the wrong place. Better still would simply useif média <= 4.0:
as given in the answers. The same applies toelif
. Therefore, I consider your question to be a typo.– Victor Stafusa