Python Syntax: Medical Insurance Project

Hey everyone, I am doing the Python Syntax: Medical Insurance Project and when I print to the terminal I’m not getting the correct math.

Heres my code:

# create the initial variables below

age = 28

sex = 0

bmi = 26.2

num_of_children = 3

smoker = 0

# Add insurance estimate formula below

insurance_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

print(“This person’s insurance cost is " + str(insurance_cost) + " dollars.”)

print("")

# Age Factor

age += 4

new_insurance_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

change_in_insurance_cost = new_insurance_cost - insurance_cost

print(“The change in cost of insurance after increasing the age by 4 years is " + str(change_in_insurance_cost) + " dollars.”)

print("")

# BMI Factor

age = 28

bmi += 3.1

new_insurace_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

change_in_insurance_cost = new_insurance_cost-insurance_cost

print(“The change in estimated insurance cost after increasing BMI by 3.1 is " + str(change_in_insurance_cost) + " dollars.”)

Here is what the terminal prints

This person’s insurance cost is 5469.0 dollars.

The change in cost of insurance after increasing the age by 4 years is 1000.0 dollars.

The change in estimated insurance cost after increasing BMI by 3.1 is 1000.0 dollars.

If I did my math right, and I think I did it should not be a 1000 dollar difference each time. I’ve checked my code several times and cant figure out what I’ve done wrong.

Thanks for the help

Hello @dev6623677446, welcome to the forums! Could you please format your code correctly?

1 Like

No problem. I don’t see an option to edit my original post so I’ll just copy and paste here!

# create the initial variables below

age = 28

sex = 0

bmi = 26.2

num_of_children = 3

smoker = 0

# Add insurance estimate formula below

insurance_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

print(“This person’s insurance cost is " + str(insurance_cost) + " dollars.”)

print("")

# Age Factor

age += 4

new_insurance_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

change_in_insurance_cost = new_insurance_cost - insurance_cost

print(“The change in cost of insurance after increasing the age by 4 years is " + str(change_in_insurance_cost) + " dollars.”)

print("")

# BMI Factor

age = 28

bmi += 3.1

new_insurace_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500

change_in_insurance_cost = new_insurance_cost-insurance_cost

print(“The change in estimated insurance cost after increasing BMI by 3.1 is " + str(change_in_insurance_cost) + " dollars.”)

Here is what the terminal prints

This person’s insurance cost is 5469.0 dollars.

The change in cost of insurance after increasing the age by 4 years is 1000.0 dollars.

The change in estimated insurance cost after increasing BMI by 3.1 is 1000.0 dollars.

If I did my math right, and I think I did it should not be a 1000 dollar difference each time. I’ve checked my code several times and cant figure out what I’ve done wrong.

Thanks for the help

Looks like a value hasn’t updated as expected. Have a very close look for typos or errors where you’ve re-used variable names. With the online ide tools like find (Ctrl+F on many web browsers) can help you do this if you can’t spot something by eye.

1 Like

Ah! I should have known! Thanks for your help!

1 Like