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!
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.
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!
Soo… I’m trying my hands on this extra question under this project but I’m not getting it.
Congratulations! In this project, you used Python lists to store estimated insurance cost data and then compare that data to actual insurance cost data.
As you’ve seen, lists are data structures in Python that can contain multiple pieces of data in a single object. As a data scientist, you’ll find yourself working with this data structure quite often. You now have a solid foundation to move forward in your data science journey!
If you’d like additional practice on lists, here are some ways you might extend this project:
insurance_cost_difference
.names
and his actual insurance cost, 2930.0
, to insurance_costs
.Happy coding!
Having problems with the * difference*
please someone should help with a solution and explanation.
This is my take on calculating the difference between actual and estimate:
insurance_cost_difference =
# estimated insurance cost for each individual
estimated_insur_cost_maria = estimated_insurance_data[0][1]
estimated_insur_cost_rohan = estimated_insurance_data[1][1]
estimated_insur_cost_valentina = estimated_insurance_data[2][1]
# actual insurance cost for each individual
actual_insur_cost_maria = insurance_data[0][1]
actual_insur_cost_rohan = insurance_data[1][1]
actual_insur_cost_valentina = insurance_data[2][1]
# difference in actual and estimated insurance cost for each individual
insurance_cost_difference_maria = float(actual_insur_cost_maria) - float(estimated_insur_cost_maria)
insurance_cost_difference_rohan = float(actual_insur_cost_rohan) - float(estimated_insur_cost_rohan)
insurance_cost_difference_valentina = float(actual_insur_cost_valentina) - float(estimated_insur_cost_valentina)
#append insurance cost difference values to insurance cost difference list
insurance_cost_difference.append((insurance_cost_difference_maria,insurance_cost_difference_rohan,insurance_cost_difference_valentina))
#print final value
print("The difference between acutal insurance cost data and the estimated insurance cost data for each individual is: " + str(insurance_cost_difference))
Not sure if there is an easier way but this works for me
Thank you very much for your suggestion