There are two main errors in your code: what justifies the error message you put and another that you probably didn’t notice since the first error would fill the second.
The function malhar
that you have defined does not have a return clause and, by default in Python, functions without this clause will return the value None
. So when you do:
while (peso_usuario > peso_desejado):
peso_usuario = malhar(idade_usuario, peso_usuario)
vezesMalhou = vezesMalhou + 1
The value of peso_usuario
will receive the value None
the first time calling the function malhar
, which justifies the error message by saying that it is not possible to verify whether None
is greater than a number (peso_usuario > peso_desejado
).
The second error is in the body of the working out function:
def malhar(idade, peso):
if (idade < 28):
peso = - 2
else:
peso = - 1
Because basically what you did was assign the value -2
if the age is less than 28 and -1
otherwise. Thus, already in the first call to this function would be as if the user’s weight became negative, which makes no sense, including physically. I believe that the idea here would be to reduce the weight by 2 (or 1, depending on age) and for this you should reverse the order the operators: instead of =-
place -=
. Or you can even simplify by returning the value (which corrects the first error):
def malhar(idade, peso):
if (idade < 28):
return peso - 2
return peso - 1
"including physically" - of course, the question does not make sense at all, but: https://physics.stackexchange.com/q/396398 | https://en.wikipedia.org/wiki/Negative_mass :-)
– hkotsubo