I am currently working through the ‘Python Control Flow: Medical Insurance Project’ and I am trying to add in some error control. Specifically for the analyze_smoker part of the code, if it works I would then do the same for analyze_bmi.
One of the inputs is smoker, which can be 0 or 1 for the program to work. I am attempting to add in an error code so that, if someone puts yes/no the program will state “Please use 1 for smoker, and 0 for non-smoker.”
However, I keep getting NameError anyways.
If someone could spare a glance i would appreciate it!
# Add your code here def analyze_smoker(smoker_value): if smoker_value == 1: print("To lower you cost, you should consider quitting smoking.") else: print("Smoking is not an issue for you.") def analyze_bmi(bmi_value): if bmi_value > 30: print("Your BMI is in the obese range. To lower your cost, you should significantly lower your BMI.") if bmi_value >= 25 and bmi_value <=30: print("Your BMI is in the overweight range. To lower your cost, you should lower your BMI.") if bmi_value >=18.5 and bmi_value <25: print("Your BMI is in a healthy range.") if bmi_value < 18.5: print("Your BMI is in the underweight range. Increasing your BMI will not help lower your cost, but it will help improve your health.") # Function to estimate insurance cost: def estimate_insurance_cost(name, age, sex, bmi, num_of_children, smoker): estimated_cost = 250*age - 128*sex + 370*bmi + 425*num_of_children + 24000*smoker - 12500 print(name + "'s Estimated Insurance Cost: " + str(estimated_cost) + " dollars.") try: analyze_smoker(smoker) except NameError: print("Please use 1 for smoker, and 0 for non-smoker.") analyze_bmi (bmi) return estimated_cost # Estimate Keanu's insurance cost keanu_insurance_cost = estimate_insurance_cost(name = 'Keanu', age = 29, sex = 1, bmi = 26.2, num_of_children = 3, smoker = yes)