0

Why did the code cause the error? I don't see any mistakes.

вес = int(input()) рост = int(input()) if вес / рост**2 < 18.5: print("Underweight") elif вес / рост**2 >= 18.5 and вес / рост**2 < 25: print("Normal") elif вес / рост**2 >= 25 and вес / рост**2 < 30: print("Overweight") elif вес / рост**2 >= 30: print("Obesity")

13th May 2023, 11:19 PM
Кальян Село
Кальян Село - avatar
4 Réponses
+ 5
ВСЯКОЧИНИ , one hint to this code: the suggested code has some *redundant* parts:   >  вес / рост**2  is calculated in each conditional case, in total it does 6 times the same. so better to do the calculation once, store it in a variable and use this variable instead: вес = float(input()) рост = float(input()) bmi = вес / рост**2 # <= added this line to calculate the bmi if bmi < 18.5: # <= modified this line     print("Underweight") elif bmi >= 18.5 and bmi < 25: # <= modified this line     print("Normal") elif bmi >= 25 and bmi < 30: # <= modified this line     print("Overweight") elif bmi >= 30: # <= modified this line     print("Obesity")
15th May 2023, 3:43 PM
Lothar
Lothar - avatar
+ 4
ВСЯКОЧИНИ the data type for рост should be float, not int. Converting the input to int causes it to lose the decimal portion of the input value.
14th May 2023, 4:41 AM
Brian
Brian - avatar
+ 4
ВСЯКОЧИНИ the data type in your code is wrong, you wrote int but it will be float | int= integer value, float=decimal value Code will be:- вес = float(input()) рост = float(input()) if вес / рост**2 < 18.5: print("Underweight") elif вес / рост**2 >= 18.5 and вес / рост**2 < 25: print("Normal") elif вес / рост**2 >= 25 and вес / рост**2 < 30: print("Overweight") elif вес / рост**2 >= 30: print("Obesity")
15th May 2023, 6:47 AM
Alhaaz
Alhaaz - avatar
+ 2
Thank you all. Apparently at night I'm really dumb
15th May 2023, 7:34 AM
Кальян Село
Кальян Село - avatar