 IMC calculator | Sololearn: Learn to code for FREE!

+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')

+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 :)

+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")

+1

the value of input 4 is hidden

0

Ouch... This one was tricky . Thank you!

0

Case 4 doesn't work out

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")