1
I’m taking my first steps in Python, and I came up with a question in the if/Else sentence, trying to solve the following exercise:
"Using a person’s height and gender as input data, construct an algorithm that calculates their ideal weight using the following formulas:
For men: (72.7*h) - 58
For women: (62.1*h) - 44.7 (h = height)
Ask for the person’s weight and tell them if they are in, overweight or underweight."
That was the logic used by me:
def main():
altura = float(input("Digite a altura do paciente: "))
sexo = input("Digite o sexo do paciente, H(Masculino) ou F(Feminino): ")
altura
if sexo == H or sexo == h:
peso = (72.7 * altura) - 58
print ("O peso ideal do paciente é: ",peso)
elif sexo == F or sexo == f:
peso = (62.1 * altura) - 44.7
print ("O peso ideal da paciente é: ",peso)
else:
print ("Sexo inválido")
pesopaciente = input("Digite o seu peso: ")
if pesopaciente < peso:
print("Você está abaixo do peso ideal.")
elif pesopaciente > peso:
print("Você está acima do peso ideal.")
else:
print("Você está na média de peso.")
main()
However, it returns the following error:
Traceback (Most recent call last):
File "python", line 12
Elif sex == F or sex == f:
^
Syntaxerror: invalid syntax
You could help me?
Grateful!
Actually, my indentation was completely wrong. I’m kind of used to Java, I had no notion that it needed to be this way. If you can take me another question, as soon as I applied the corrections you gave me, I noticed that it is also necessary to give a tab on the personal line = input("Type your weight: "), would you know me why? Thank you very much, Filipe!
– Mateus Binatti
Why is he inside the
main
. If you took it out of indentation, both the line that you have sayspesopaciente = input("Digite o seu peso: ")
as the rest of the if would be out of the main, which is not what you want, I believe...– Filipe Teixeira