+ 1

IMC calculator

in the imc calculator project my code does not pass input 4 and I don't know why, the others if it exceeds them weight = int(input()) height = float(input()) imc = weight/(height**2) if imc <= 18.5: print ('Underweight') elif imc > 18.5 and imc <= 24.9: print ('Normal') elif imc >=25 and imc <= 29.9: print ('Overweight') elif imc >30: print ('Obesity')

5th May 2021, 6:25 PM
Richard
Richard - avatar
7 Respostas
+ 6
The way you setup your conditions will actually fail if the imc is equal to something like 29.95. It would work better if you set them up this way: if imc <= 18.5: print("Underweight") elif imc <= 25: print("Normal") elif imc <= 30: print("Overweight") else: print("Obesity") You might need to adjust the values to fit your case but I hope this will help you out! Have fun coding :)
5th May 2021, 6:42 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 4
The same thing happens to me, I am in that problem and I came up with this, try not to leave any free space between the numbers but nothing: #IMC p=int(input()) a=float(input()) imc=p/a**2 if imc<18.5 and imc>=0: print("Underweight") elif imc>=18.5 and imc<=24.9: print("Normal") elif imc>24.9 and imc<=29.9: print("Overweight") elif imc>29.9: print("Obesity")
5th May 2021, 10:15 PM
Kevin Huaripata
Kevin Huaripata - avatar
+ 1
the value of input 4 is hidden
5th May 2021, 6:26 PM
Richard
Richard - avatar
+ 1
Thanks
5th May 2021, 7:38 PM
Richard
Richard - avatar
0
Ouch... This one was tricky . Thank you!
28th Jun 2021, 9:00 PM
César Díaz Amat
0
Case 4 doesn't work out
28th Jul 2021, 12:41 AM
Jorge Osornio
Jorge Osornio - avatar
0
Hey, it’s work for me! weight=int(input()) height=float(input()) imc=float(weight/(height ** 2)) if imc>0 and imc<18.50: print("Underweight") elif imc>=18.50 and imc<=24.99: print("Normal") elif imc>=25.00 and imc<=29.99: print("Overweight") elif imc>=30.00: print("Obesity")
22nd May 2022, 11:33 PM
Cristian Ferrer