0

Why do the variables need to be switched?

When I ran this code with the 'height' and 'weight' variables like below, it wouldn't work...but when I switched it so 'weight' went first, the code worked. Why is that? height = float(input()) weight = float(input()) BMI = weight/(height*height) if BMI < 18.5: print ("Underweight") elif BMI >= 18.5 and BMI < 25: print ("Normal") elif BMI >= 25 and BMI < 30: print ("Overweight") elif BMI >=30: print ("Obesity")

24th Nov 2021, 8:52 PM
YoYo Ma
1 Odpowiedź
+ 6
say, for example, you entered: 60 and 150 for your input: 60 / (150 * 150) = .0027 AND 150 / (60 * 60) = .042 would be the bmi depending on which was supplied first. And as you can see, the have very differnt solutions. Also, input is specifically given in an order for these challenges.
24th Nov 2021, 9:04 PM
Slick
Slick - avatar