Issue
I am trying to create a program that will calculate the BMI of a person as my homework. I am getting "unexpected indent" error in line 9 which is ***print ("Your BMI is: ",BMI). I have moved the indent back and forth to correct it but still not working. Please help as I am only a beginner. Thank you in advance.
user_input = float(input("Let's calculate your BMI! Please select if you 'K' for kilograms and L for pounds for your weight: ")).upper
if user_input == "K":
user_input_weight_kgs = float(input("Weight in kgs.:"))
user_input_height = float(input("Height by inches: "))
user_input_age = (input("Age:"))
BMI_for_kgs = float(user_input_weight / (user_input_height **2))
print ("Your BMI is: ",BMI)
if BMI < 18.5 :
print ("Under Weight")
elif BMI < 26:
print ("Normal Weight")
else:
print ("Over Weight")
elif user_input == "L":
user_input_weight_lbs = float(input("Weight in lbs.: "))
user_input_height = float(input("Height by inches: "))
user_input_age = (input("Age:"))
BMI_for_lbs = float((user_input_weight * 703) / (user_input_height **2))
print ("Your BMI is: ",BMI)
if BMI < 18.5 :
print ("Under Weight")
elif BMI < 26:
print ("Normal Weight")
else:
print ("Over Weight")
elif guess.isnumeric():
print ("Please select an alphabet only! Letter 'K' or 'L'")
elif len(guess) > 1:
print ("Please choose a single alphabet only! Letter 'K' or 'L'")
elif len(guess) == 0:
print ("You need to enter a letter! Letter 'K' or 'L'")
else:
break
Solution
The issue is that the line 9 (print line) is not indented properly, here is the fix:
if user_input == "K":
user_input_weight_kgs = float(input("Weight in kgs.:"))
user_input_height = float(input("Height by inches: "))
user_input_age = (input("Age:"))
BMI_for_kgs = float(user_input_weight / (user_input_height **2))
print ("Your BMI is: ",BMI)
if BMI < 18.5 :
print ("Under Weight")
elif BMI < 26:
print ("Normal Weight")
else:
print ("Over Weight")
elif user_input == "L":
user_input_weight_lbs = float(input("Weight in lbs.: "))
user_input_height = float(input("Height by inches: "))
user_input_age = (input("Age:"))
BMI_for_lbs = float((user_input_weight * 703) / (user_input_height **2))
print ("Your BMI is: ",BMI)
if BMI < 18.5 :
print ("Under Weight")
elif BMI < 26:
print ("Normal Weight")
else:
print ("Over Weight")
elif guess.isnumeric():
print ("Please select an alphabet only! Letter 'K' or 'L'")
elif len(guess) > 1:
print ("Please choose a single alphabet only! Letter 'K' or 'L'")
elif len(guess) == 0:
print ("You need to enter a letter! Letter 'K' or 'L'")
else:
break
You should only indent code inside a code block. Indenting starts a block and unindenting ends it. There are no explicit braces, brackets, or keywords that end a block of code in Python.
EDIT
to answer the additional question (in the comments):
Your problem is that you are expecting a string either "K" or "L" it seems but you are trying to convert that string to a float. That should indicate that something is wrong. Additionally, you are not actually calling upper()
which is another problem (unless your intent is to call user_input()
to get the uppercase value of your string, which I think is not necessary here). To solve:
user_input = input("Let's calculate your BMI! Please select if you 'K' for kilograms and L for pounds for your weight: ").upper()
Answered By - Cyzanfar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.