+ 1
BMI Calc
Hello folks, I am in the process of learning Python and I am kinda stuck in the BMI Calc challenge this is my Code: wt = int(input()) ht = float(input()) bmi = wt/(ht**ht) if bmi < 18.5: print("Underweight") elif bmi >= 18.5 and bmi < 25: print("Normal") elif bmi >= 25 and bmi < 30: print("Overweight") else: print("Obesity") While Challenges 1-3 are all with green checkmarks, 4-5 are not and they are locked so I can't even tell what is the issue. maybe someone can spot an obvious error cause i have no clue what else I could shift around. thanks in advance
3 Respostas
+ 3
Hello. Looking great so far.
Remember,
bmi = weight/height**2
Weight should be a float
also, the “and” in your elif statements are unnecessary, instead you could use
elif 18.5 <= bmi < 25:
+ 2
thank you it was mostly the ht**ht instead of ht**2, i somehow got that jumbled up. now that I read in your answer it made more sense, also thank you for pointing the "issue" with the "and" out, helps streamline it better.
0
To further streamline your logic, there is no need to check bmi >= 18.5 after already checking bmi < 18.5. Likewise for the other thresholds. Here it is further reduced:
if bmi < 18.5:
print("Underweight")
elif bmi < 25:
print("Normal")
elif bmi < 30:
print("Overweight")
else:
print("Obesity")
See? Your code could lose some weight!