Python Classes: Medical Insurance Project Step 7

Hello,

I am working on the Python Classes: Medical Insurance Project. I am trying to create the update_age() method. I was able to get the age to update, but now I can’t get the updated insurance cost to print out.

Here is my code for the Patient class:

class Patient: def __init__(self, name, age, sex, bmi, num_of_children, smoker): self.name = name self.age = age self.sex = sex self.bmi = bmi self.num_of_children = num_of_children self.smoker = smoker def estimated_insurance_cost(self): self.estimated_insurance_cost = 250 * self.age - 128 * self.sex + 370 * self.bmi + 425 * self.num_of_children + 24000 * self.smoker - 12500 print("{}'s estimated insurance costs is {} dollars.".format(self.name, self.estimated_insurance_cost)) def update_age(self, new_age): self.age = new_age print("{} is now {} years old.".format(self.name, self.age)) self.estimated_insurance_cost() patient1 = Patient("John Doe", 25, 1, 22.2, 0, 0) patient1.estimated_insurance_cost() patient1.update_age(26)

Can anyone explain why I am getting this error?

You have a function estimated_insurance_cost, but the function also has a variable self.estimated_insurance_cost which contains a float.
The estimated_insurance_cost variable replaces the estimated_insurance_cost method.

One way to solve that would be to change the names of one of those;
for example, change the function’s name to be estimate_insurance_cost (no d) instead.

That fixed it! Thanks!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.