'Not sure why the variable isn't becoming defined in my if / elif statement
I'm currently taking a 100 day python course and I am at the BMI calculator part 2. Here is the code I created:
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
BMI = round(weight / height ** 2, 1)
if BMI < 18.5:
category = underweight
if 18.5 >= BMI <= 25:
category = normal_weight
elif 25 >= BMI <= 30:
category = slightly_overweight
elif 30 >= BMI <= 35:
category = obese
elif BMI > 35:
category = clinically_obese
print("Your BMI is " + str(BMI) + ", you are " +category+ ".")
This is the error I am getting :
File "main.py", line 18, in <module>
print("Your BMI is " + str(BMI) + ", you are " +category+ ".")
NameError: name 'category' is not defined
➜
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
