I’m doing a fat burning heart rate and BMI calculator. It needs to account for incorrect inputs and loop back to request the correct input then move on to the next request for input.
#Calculate ideal fat burning heart rate and BMI
#(220 - age) * .7 for fat burning heart rate
#BMI = 703 * lbs / height**2 (in)
print("Welcome to the Weber State University Performance Lab!")
print("Please utilize the following calculator to find your ideal fat burning heart rate and BMI.")
#Age entry
try:
age = float(input("Please enter your age: "))
if age <= 0:
raise TypeError ("Please enter a number greater than zero.")
except ValueError:
print("Invalid input.")
print("Please enter your age in numeric format.")
except TypeError as err:
print(err)
except:
print("Invalid input.")
#Height entry
try:
height = float(input("Please enter your height in inches: "))
if height <= 0:
raise TypeError ("Please enter a number greater than zero.")
except ValueError:
print("Invalid input.")
print("Please enter your height in inches in numeric format.")
except TypeError as err:
print(err)
except:
print("Invalid input.")
#Weight Entry
try:
weight = float(input("Please enter your weight in pounds: "))
if weight <= 0:
raise TypeError ("Please enter a number greater than zero.")
except ValueError:
print("Invalid input.")
print("Please enter your weight in pounds in numeric format.")
except TypeError as err:
print(err)
except:
print("Invalid input.")
print("Your age:", age, "years old.")
print("Your height:", height, "inches tall.")
print("Your weight", weight, "lbs")
print("Your ideal fat burning heart rate is", float(round((220 - age) * .7)), "BPM.")
print("Your Body Mass Index is", float(round((703 * (weight / height**2)))))
I tried putting it in a while loop just has the first input looping even when I put in a break. It just won’t move on to the next portion of the loop.
New contributor
Stephanie Davi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.