I am trying to code a BMI calculator. I am trying to make sure the user input to be a float only, so I used except
, but I couldn't make it loop the check.
def error_handeling():
try:
weight = float(input("enter your weight in KG : "))
except ValueError:
weight = float(input("enter your REAL weight in KG : "))
for i in range(100):
error_handeling()
while weight < 2.0:
print("enter a valid weight")
weight = float(input("enter your weight in KG : "))
if False:
break
height = float(input("enter your height in Meters: "))
while height < 0.5 or height > 2.2:
print("enter a valid height ")
height = float(input("enter your height in meters : "))
if False:
break
BMI = weight / (height**2.0)
print("your bmi is : " + str(BMI))
if BMI < 18.5:
print("you're underweight EAT MORE !!")
if BMI > 18.5:
print("you're overweight EAT LESS + practise sport !!")
if BMI == 18.5:
print("you're in perfect weight")