Python Lists: Medical Insurance Project

I’m stuck on Task 8 which asks me to Print estimated_insurance_data

I’m getting a NameError which says maria_insurance_cost is not defined, but it is on line 20

any tips? thank you!

You do have maria_insurance_cost defined on line 20, but look at which line is throwing the error.

Hint if needed

Normally a program can’t perform an action with a variable that has not yet been initialized.

so line 14 is throwing the error, but why aren’t lines 15 and 16 throwing the same errors because I can’t see a difference between them?

and sorry I don’t understand which variable hasn’t been initialised?

thank you for your help!

Actually if you fix line 14, 15 and 16 will throw the same error, but with the variables rohan_insurance_cost and valentina_insurance_cost because they have not been initialized yet either.
The reason it doesn’t throw the errors now is because of how the Python interpreter works. Python files are compiled on running, this means that it will only catch the first error and then stop the program.

Defined might have been a better word to use on my part.
If you look at the error you are getting, it’s a NameError stating that:

name maria_insurance_cost is not defined

This means that within your program there you are trying to use the name maria_insurance_cost but it has not been defined yet. As such the interpreter doesn’t know what the name means and it can’t do anything with it. In Python you need to declare a variable before it is used in the code. For example you can type:

message = "Hello World"
print(message)

But you can’t do:

print(message)     # message has not been created yet and can't be used
message = "Hello World"

aah ok thank you got it! sorry I was being slow

so I’ve just defined each person’s insurance cost, e.g. maria_insurance_cost = 4150

thank you!

1 Like