+ 2
(BMI calculator) Can someone please be kind enough to find the errors in this Python code please.🙃🤓
Weight= int(input()) height= float (input()) BMI =( weight/height**2) if BMI >=30: print ("obese") elif (BMI>=30 and<=18.5): print("Normal") elif BMI<= 18.5 : print (" Underweight") else : print("Overweight")
6 Antworten
+ 7
Nethmi Pallekankanamge , there are many errors in your code: alignment, names of the variables (once weight starts with capital letter, once with lowercase letter), logical errors ( "<" instead of ">" and vice versa), wrong message "obese" instead of "Obesity" etc. Look at the corrected code:
weight= int(input())
height= float (input())
BMI =(weight/height**2)
if BMI >=30:
print ("Obesity")
elif (BMI<=25 and BMI>=18.5):
print("Normal")
elif BMI< 18.5:
print ("Underweight")
else :
print("Overweight")
+ 1
Weight should be a float type not int as it is dealing with a float
+ 1
weight= int(input())
height= float (input())
BMI =( weight/height**2)
if BMI >=30:
print ("Obesity")
elif (BMI<25 and BMI>=18.5):
print("Normal")
elif BMI< 30 and BMI>=25:
print ("Overweight")
else :
print("Underweight")
+ 1
Atul [Inactive] thank you for taking the time to answer my question ☺️
0
Kamil Hamid i changed it ..but it still says there’s an error in indentation and i still cant fix it 🙁Thanks for the tip btw
0
TheWh¡teCat 🇧🇬 🙏Thank you so much for this ,i corrected my code ,now and it finally works!!! 😊✨Thanks a lot again