0

Hi, I'm struggling with the Python model for quiz the BMI calculator

height = float(input()) weight = float(input()) BMI = (weight/(height**2)): if BMI < 18.5: print("Underweight") elif BMI >18.5 and BMI <25: print("Normal") elif BMI >=25 and <30: print("Overweight") elif BMI >30: print("Obesity") This is what I have so far and I've tried for a good minute, but I still can't figure out how to properly code it. Would love a walk-through if I could get one

18th Nov 2022, 11:30 PM
fivestar_ -5555
fivestar_ -5555 - avatar
2 Respostas
+ 1
fivestar_ -5555 the logic is a little bit flawed. But first, the order of input parameters is swapped. First get weight, then height. Logic error: What happens if BMI is exactly 18.5? Or 30? Logic refinement: It is unnecessary to test the thresholds more than once. If BMI is not below the threshold, then of course it must be equal or above. You may remove all the tests for > and >=. (After all, including extra tests is what broke your logic). The final portion of the if statement can be a simple else:.
19th Nov 2022, 12:27 AM
Brian
Brian - avatar
+ 1
#your code goes here weight = int(input()); height = float(input()); x = weight/float(height*height); if x < 18.5: print('Underweight') if x>=18.5 and x<25: print("Normal") if x >= 25 and x < 30: print('Overweight') if x >= 30: print('Obesity')
20th Nov 2022, 6:18 PM
Ajit Kumar
Ajit Kumar - avatar