Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON. im writing a BMI code that asks users to input numbers to calculate their bmi. however, if a user were to input a negative
PYTHON. im writing a BMI code that asks users to input numbers to calculate their bmi. however, if a user were to input a negative or some abnormal number like 0 or "cat," i want the program to produce an error message instead of crashing or showing a traceback error. i've tried to do try/except, raise, while loops, but nothing works. make the program report input errors instead of crashing or producing error outputs. PLEASE INCLUDE COMMENTS SO I CAN LEARN. thank you. #Introduce BMI Calculator print ('Welcome to BMI Calculator!') #Ask if user would like to use Metric or Imperial units input1 = input ('Would you like to input Metric units or Imperial units? ')
#If Imperial... If Metric... Calculate BMI... if input1 == 'imperial': heightIN = float(input('Input your height in Inches (in): ')) weightLB = float(input('Input your weight in Pounds (lbs):' )) BMI = round(((weightLB/(heightIN*heightIN))*703), 2) if BMI >= 19 and BMI <= 24: print ('Your BMI is', BMI, 'so, you are healthy weight!') elif BMI >= 25 and BMI <= 29: print ('Your BMI is', BMI, 'so, you are overweight!') elif BMI >= 30 and BMI <= 39: print ('Your BMI is', BMI, 'so, you are obese!') elif BMI > 39: print ('Your BMI is', BMI, 'so, you are extremely obese!') elif BMI < 19: print ('Your BMI is', BMI, 'so, you are underweight!') elif input1 == 'metric': heightCM = float(input('Input your height in Centimeters (cm): ')) weightKG = float(input('Input your weight in kilograms (kg): ')) heightM = heightCM*0.01 BMI = round((weightKG/(heightM*heightM)), 2) if BMI >= 19 and BMI <= 24: print ('Your BMI is', BMI, 'so, you are healthy weight!')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started