0

Python imc doesn't work

Hi, everyone. I'm trying to do the imc calculator in python and I wrote this: alt=float(input()) peso=float(input()) imc=peso/(alt**2) if imc<18.5: print ("Underweight") if 24.9>=imc>=18.5: print ("Normal") if imc>=25 and imc<=29.9: print ("Overweight") if imc>30: print ("Obesity") I tried to use elif, but it didn't work. So that's why I left the code as it is shown. The funny thing is that I created a new code file (inside the sololeran app) and it worked. For some reason, this code doesn't pass the tests in the imc calculator. Can you please help me and tell me where I am mistaken? I appreciate your help!

19th May 2022, 6:48 PM
VAl
VAl - avatar
3 ответов
+ 1
Your code doesn't work for 24.9 < imc < 25 and 29.9 < imc <= 30... so you should make some changes in imc ranges to get output for any imc.
19th May 2022, 7:36 PM
MortezaXY
MortezaXY - avatar
0
Can you add task description? edit: VAl is there asked to calculate : imc = peso/alt**2 or imc = alt / peso**2 also missing cases when imc = 25 and 30
19th May 2022, 6:57 PM
Jayakrishna 🇮🇳
0
Inputs are swapped. First input peso, then input alt. The thresholds are 18.5, 25, and 30. So make the logic based on those thresholds alone. if imc<18.5: elif imc<25: elif imc<30: else:
19th May 2022, 8:30 PM
Brian
Brian - avatar