+ 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

13th Oct 2021, 7:09 PM
D S
D S - avatar
3 Réponses
+ 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:
13th Oct 2021, 7:32 PM
Madi
Madi - avatar
+ 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.
13th Oct 2021, 7:42 PM
D S
D S - avatar
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!
14th Oct 2021, 8:22 AM
Brian
Brian - avatar