Lists Medical Insurance Project - Extra

Hi everyone.

So I was doing the extra exercises in the medical insurance project and everything is perfect except that when doing the final list with the data from ‘Akira’. His difference (which should be 0) is not showing as 0. What might I be doing wrong?

Link to the exercise: https://www.codecademy.com/paths/data-science-foundations/tracks/dsf-python-fundamentals-for-data-science-part-i/modules/dsf-python-lists/projects/ds-python-lists1-project

My Code:

Function to estimate insurance cost:

def estimate_insurance_cost(name, age, sex, bmi, num_of_children, smoker):

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

print(name + “'s Estimated Insurance Cost: " + str(estimated_cost) + " dollars.”)

return estimated_cost

Estimate Maria’s insurance cost

maria_insurance_cost = estimate_insurance_cost(name = “Maria”, age = 31, sex = 0, bmi = 23.1, num_of_children = 1, smoker = 0)

Estimate Rohan’s insurance cost

rohan_insurance_cost = estimate_insurance_cost(name =

“Rohan”, age = 25, sex = 1, bmi = 28.5, num_of_children = 3, smoker = 0)

Estimate Valentina’s insurance cost

valentina_insurance_cost = estimate_insurance_cost(name = “Valentina”, age = 53, sex = 0, bmi = 31.4, num_of_children = 0, smoker = 1)

Estimate Akira’s insurance cost

akira_insurance_cost = estimate_insurance_cost(name = “Akira”, age = 19, sex = 1, bmi = 27.1, num_of_children = 0, smoker = 0)

Add your code here

names = [“Maria”, “Rohan”, “Valentina”, “Akira”]

insurance_costs = [4150.0, 5320.0, 35210, 2149]

insurance_data = zip(names, insurance_costs)

list_insurance_data = list(insurance_data)

print("This is the actual insurance data: " + str(list_insurance_data))

estimated_insurance_data =

estimated_insurance_data.append((“Maria”, maria_insurance_cost))

estimated_insurance_data.append((“Rohan”, rohan_insurance_cost))

estimated_insurance_data.append((“Valentina”, valentina_insurance_cost))

estimated_insurance_data.append((“Akira”, akira_insurance_cost))

print(“This is the estimated insurance data” + str(estimated_insurance_data))

maria_insurance_difference = 4222 - 4150

rohan_insurance_difference = 5442 - 5320

valentina_insurance_difference = 36368 - 35210

akira_insurance_difference = 2149 - 2149

insurance_cost_difference = [maria_insurance_difference, rohan_insurance_difference, valentina_insurance_difference, akira_insurance_cost]

print(insurance_cost_difference)

names_insurance_cost_difference = zip(names, insurance_cost_difference)

list_names_insurance_cost_difference = list(names_insurance_cost_difference)

print("This is the difference between estimated and actual insurance for each individual: " + str(list_names_insurance_cost_difference))

Edit:

The output of the final list sets everything perfect except the value for Akira’s difference which instead of 0 is 2149, like if the operation is not being performed but it is strange since the difference for all other individuals show up perfectly.

You used a wrong number when you calculated akira_insurance_difference, the actual cost number should be 2930.

Also, consider using indices to get the differences:

maria_insurance_difference = list_insurance_data[0] - estimated_insurance_data[0]
rohan_insurance_difference = list_insurance_data[1] - estimated_insurance_data[1]

And if you’ve learned loops, you could loop through the stuff using the indices, or do a list comprehension.

Thank you very much! Found it out just now before checking the answers but your suggestion on loops is great. Learning those right now so might go back to the projects to apply them once I get the concepts.