Why am I getting a syntax error when reassigning a variable?

In lesson 3.5, I get a syntax error when trying to reassign the bmi variable back to its original value of 26.2 .

File “script.py”, line 24
bmi = 26.2
^
SyntaxError: invalid syntax

Thank you in advance!

Lesson is here:

https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-syntax/projects/ds-python-syntax-project

Hi there, and welcome to the forums!

It would be great if you could post your full code so we can see the context in which it sits, this can help with debugging the issue.

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.”)

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(“People who are four years older have estimated insurance costs that are " + str(change_in_insurance_cost) + " dollars different.”)

BMI Factor

age = 28

bmi += 3.1

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 estimated insurance cost after increasing BMI by 3.1 is " + str(change_in_insurance_cost) + " dollars.”

Male vs. Female Factor

bmi = 26.2

sex = 1

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 estimated insurance cost after increasing BMI by 3.1 is " + str(change_in_insurance_cost) + " dollars.”

Extra Practice

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

Note the missing close parenthesis on that print function?


Quite often, when you get a syntax error on one line, and you can’t see anything wrong with that line, check the line before it for things like missing parentheses or quotation marks.

2 Likes

That worked. Thank you!

1 Like