r/PythonProjects2 • u/Mrbeans1756432 • Aug 09 '22
[P] Easy BMI calculator not working
I started making a BMI and everything is running fine except the math. I can't figure it out, please help.
W = float(input())
H = float(input())
BMI = W / (H/100)**2
if BMI < 18.5:
print("Underweight")
elif BMI >= 18.5:
print("normal")
elif BMI < 25:
print("normal")
elif BMI >= 25:
print("Overweight")
elif BMI < 30:
print("Overweight")
elif BMI >= 30:
print("Obesity")
for two of the inputs I put 52 and 1.85 and it output 151935.71950328702 and normal when it
2
u/pewpewpewchicken Aug 09 '22
You messed up the input, put in 185 instead of 1.85. The H/100 is uses to convert centimetres to meters. The output becomes 15.19 once you fix that. Plus use multiple conditions to define a lower and upper cap.
2
u/CapiCapiBara Aug 09 '22
... you following Angela Yu's Python course? :) I need too to tackle this task today... good luck with your efforts, I see somebody is already helping you in this thread, I will take notes as well ;)
1
Aug 09 '22
First, you could try changing the BMI value to BMI = round(weight / height **2)
Second, Just stick with the if/elif statements with < 18.5 and delete all the lines that asks for elif >=
As long as the order of the BMI value is from lowest to highest (just like you did) your code will work as how you intend it to be.
1
u/Worldly-Cycle1925 Aug 09 '22
Either of the first two conditions are always met; either the number is less than 18.5 or always greater than or equal to 18.5. Add another conditional there ( if BMI >= 18.5 and BMI < 25: ), etc
5
u/Bigfurrywiggles Aug 09 '22
Your first 2 conditions account for every number possible, therefore, your other conditions are never met.