Python Classes: Medical Insurance Project no.7

image
I don’t get this. here’s my code. where will I put this self.estimated_insurance_cost() . so it will update the cost based on the new age
def update_age(self, new_age):

self.age = new_age

return "{Name} is now {Age} years old.".format(Name = self.name, Age = self.age)

Do you have a link to the project itself? There’s not quite enough information here to be sure. It sounds like you like you need to add that line within a function called update_age following an update to the .age attribute.

That is the link for the project. I am struggling too… Thank you! https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-classes/projects/ds-python-classes-project

Have you successfully created a method in part 5 called .update_age? The instructions state insurance cost should be re-estimated once the age has been updated. As per the hint above if your original .estimated_insurance_cost method is correct you should see the given string output.

def update_age(self, new_age):
    self.age = new_age
    return "{Name} is now {Age} years old.".format(Name = self.name, Age = self.age)

here is the method. the problem is how do I call the estimated_insurance_cost() within the method in update_age(). because when I’m printing “print(patient1.update_age(50))” it updates the age but when I’m printing the estimated_insurance_cost(), it stays with the old age. I don’t know the syntax to edit in update_age method.

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

here’s the link, I’m sorry to bugged you but I’m doing the right thing, my code was right. I must skipping the age 26 that’s why my answer in the hint does not match. so I thought is doesn’t change.

thanks for you help! analyzing through your code deeply and step by step might cure the error.

Consider breaking down your query to its simplest form and posing it as a query on the forums. As this is a learning environment and copy-pasting is unlikely to teach you anything it’s not appropriate to ask for an answer. Spend the time to work out exactly what you’re stuck on and have a nosey through this FAQ which details the best way to ask a question- FAQ: How to ask good questions.

2 Likes

Hi, were you able to find a way to update the estimated insurance cost based on the new age value? I’m stuck in that same part

class Patient:
def init(self, name, age, sex, bmi, num_of_children, smoker):
self.name = name
self.age = age
# add more parameters here
self.sex = sex
self.bmi = bmi
self.num_of_children = num_of_children
self.smoker = smoker

def estimated_insurance_cost(self):
estimated_cost = 250 * self.age - 128 * self.sex + 370 * self.bmi + 425 * self.num_of_children + 24000 * self.smoker - 12500
print(self.name + ‘‘s estimated insurance costs is ’ + str(estimated_cost) + ’ dollars.’)
return self.name + ’ is now ’ + str(self.age) + ’ years old.’

def update_age(self):
return self.estimated_insurance_cost()

patient1 = Patient(“John Doe”, 25, 1, 22.2, 0, 0)

print(patient1.update_age())