I am trying to create a code that will calculate the BMI of a person, and I have provided an option to the user to enter they gender from the options provided.
If the user selects some other option I want the program to quit and it does as expected, however when a user selects the right option Male
or Female
program is quitting and not going to next line asking for user_weight
:
enter_gender = input("please enter the gender Male / Female: ")
if enter_gender .lower() not in ("Male", "Female"):
quit()
user_weight = float(input("please enter your weight: "))
user_height = float(input("please enter your height in centimeters: "))/100
square_height = (user_height*user_height)
BMI = user_weight//square_height
print(f"your current BMI is {BMI}")
if BMI < 12:
print("You are BMI is below ")
elif BMI < 25:
print("Your are Healthy")
elif BMI <= 30:
print("print over weight")
CodePudding user response:
Any string converted to lowercase cannot be equal to either Male
or Female
. Change it to:
if enter_gender.lower() not in ("male", "female"):
As a side note, you don't seem to be taking the gender into account later in your code.
CodePudding user response:
It is because you are checking an impossible condition
It is either you check if enter_gender not in ("Male", "Female"): if you want the user to enter Male or Female
or you check if enter_gender.lower() not in ("male", "female"): if you want the user to enter male or female
or you can remove the conditional check completely because it doesn't seem you are using it
enter_gender = input("please enter the gender Male / Female: ")
**if enter_gender not in ("Male", "Female"):**
quit()
user_weight = float(input("please enter your weight: "))
user_height = float(input("please enter your height in centimeters: "))/100
square_height = (user_height*user_height)
BMI = user_weight//square_height
print(f"your current BMI is {BMI}")
if BMI < 12:
print("You are BMI is below ")
elif BMI < 25:
print("Your are Healthy")
elif BMI <= 30:
print("print over weight")