+ 1
Python for Beginners
Hi, I try learning to code on my own and like Python. I started with the Beginners`Course and can´t make progress for three days cuz I´m stuck with this BMI Calculator Task.. Here´s my code so far: #BMI Calculator weight = int(input()) print("Your weight:" + weight) height = int(input()) print("Your height:" + str(height) bmi = ( weight / ( height**2) ) if (bmi < 18.5) : out("Underweight") elif (bmi >= 18.5) or (bmi < 25) : out("Normal") elif (bmi >= 25) or (bmi < 30) : out("Overweight") else: if bmi >= 30 : out("Obesity") I´m thankful for every help. I just can´t find my mistake. Have a good day!
3 Respuestas
+ 4
There are a few problems.
- stop printing anything except the output the problem describes. I commented out your extra lines below.
- replace int with float. You need to process inputs with decimal values in it. Heights like "1.7" are given and int will treat that the same as "1".
- replace "out" with "print". out isn't defined in python.
- replace your "or" with "and".
- very minor: remove the unneeded brackets in your if-statement conditions just to have cleaner code.
All of which are fixed below:
weight = float(input())
# print("Your weight:" + weight)
height = float(input())
# print("Your height:" + str(height)
bmi = ( weight / ( height**2) )
if bmi < 18.5:
print("Underweight")
elif bmi >= 18.5 and bmi < 25:
print("Normal")
elif bmi >= 25 and bmi < 30:
print("Overweight")
else:
if bmi >= 30 :
print("Obesity")
0
Hi! First of all delete all lines with prints "Your...
0
print("Thank you! \n
This helped me a lot!")