I understand this question has been asked before but I cant find a working solution. I'm new to Python and need to create a BMI calculator that will allow the user to enter multiple BMI's, but I can't get it to loop back to the beginning sucessfully. I've tried 2 ways and neither work.
Here's what I have for the first one, but this one wont run as "continue not in loop": `
while True: print("BMI Calculator") weight = float(input("\nPlease enter your weight in KG: ")) height = float(input("\nPlease enter your height in metres: ")) bmi = weight/(height*height) if bmi <= 18.5: print("Your BMI is", bmi,"which means you are underweight.") elif bmi > 18.5 and bmi < 25: print("Your BMI is: ", bmi, "which means you are normal") elif bmi > 25 and bmi < 30: print("Your BMI is: ", bmi, "which means you are overweight") elif bmi > 30: print("Your BMI is: ", bmi, "which means you are obese") else: print("There was an error with your input, Sorry.") while True: answer = input("Would you like to enter another? key y/n: ") if answer in ("y", "n"): break print("Invalid Input") if answer == "y": continue else: input("\nPress the enter key to exit") break `
The other one I have is this, but it prints BMI Calculator and then stops: `
def start(): print("\nBMI Calculator") weight = float(input("\nPlease enter your weight in KG: ")) height = float(input("\nPlease enter your height in metres: ")) bmi = weight/(height*height) if bmi <= 18.5: print("Your BMI is", bmi,"which means you are underweight.") elif bmi > 18.5 and bmi < 25: print("Your BMI is: ", bmi, "which means you are normal") elif bmi > 25 and bmi < 30: print("Your BMI is: ", bmi, "which means you are overweight") elif bmi > 30: print("Your BMI is: ", bmi, "which means you are obese") else: print("There was an error with your input, Sorry.") answer = input("Would you like to enter another? key y/n: ") while answer == "y": start() answer = None if answer == "n": input("\nPress the enter key to exit") `