Python Forum

Full Version: BMI code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi recently i started learning python my first project is BMI calculator after coding in (python 3.11) when i execute my code i get error saying float' object cannot be interpreted as an integer any help is much appreciated
my BMI coding:
weight = float(input('your weight in kg?:'))
height = float(input ('your height in cm?:'))
BMI = weight/(height/100)**2
print ('your BMI is', BMI)
if BMI < 18.5:
    print  ("under weight")
if BMI > 25:
    print  ("over weight")
if BMI in range(18.5 , 24.9):
    print  ("your BMI is IDEAL")
thanks in advance
You cannot use float numbers for start, stop, step in range(start, stop, step). This is what is giving the error. Also, range does not do what you think it does. You should read up about range() because you'll be using it a lot.

Do you need this?
if BMI in range(18.5 , 24.9):
    print  ("your BMI is IDEAL")
To get here we already know that the bmi >= 18.5 and that bmi <= 25 because the earlier if statements already caught all under and overweight cases. Think about the problem first, then think about the code.
(Sep-05-2023, 03:49 PM)deanhystad Wrote: [ -> ]You cannot use float numbers for start, stop, step in range(start, stop, step). This is what is giving the error. Also, range does not do what you think it does. You should read up about range() because you'll be using it a lot.

Do you need this?
if BMI in range(18.5 , 24.9):
    print  ("your BMI is IDEAL")
To get here we already know that the bmi >= 18.5 and that bmi <= 25 because the earlier if statements already caught all under and overweight cases. Think about the problem first, then think about the code.
tnx Mod you're right it was simple than i thought range() function was really bad i only needed <= and >= .thanks for advice