Python Classes: Medical Insurance Project final part

Hello, I am not sure how to complete the final part of this project if someone could point me in the right direction please and thank you!

  • Update the class so that users can upload lists of patient data rather than just individual numbers.

Python Classes | Codecademy

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):
    try:
      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 cost is " + str(estimated_cost) + " dollars.")
    except: 
      print('Is your entry for age/sex/bmi/num_of_children/smoker in integer form?')

  def update_age(self, new_age):
    self.age = new_age
    print(self.name + " is now " + str(self.age) + " years old.")
    self.estimated_insurance_cost()

  def update_num_of_children(self, new_num_of_children):
    self.num_of_children = new_num_of_children
    if self.num_of_children == 1:
      print(self.name + " has " + str(self.num_of_children) + " child.")
    else:
      print(self.name + " has " + str(self.num_of_children) + " children.")
    self.estimated_insurance_cost()

  def update_bmi(self, new_bmi):
    self.bmi = new_bmi
    
    print(self.name + "'s new updated BMI is: " + str(new_bmi))
    self.estimated_insurance_cost()

  def update_smoking_status(self,new_smoking_status):
    self.smoker = new_smoking_status
    if new_smoking_status == 1:
      print(self.name + " is a smoker.")
    else:
      print(self.name + " quit smoking")
    self.estimated_insurance_cost()

  def patient_profile(self):
    patient_information = {}
    patient_information["name"] = self.name
    patient_information["age"] = self.age
    patient_information["sex"] = self.sex
    patient_information["bmi"] = self.bmi
    patient_information["num_of_children"] = self.num_of_children
    patient_information["smoker"] = self.smoker

    return patient_information

  


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

print(patient1.name)
    
patient1.update_age(26)

patient1.update_num_of_children(1)

patient1.update_num_of_children(2)

patient1.update_bmi(24.6)

patient1.update_smoking_status(1)

print(patient1.patient_profile())

I believe the intention is to alter your class so that behaves the same as your original one but it can be called in the following way-

patient_data = ["John Doe", 25, 1, 22.2, 0, 0]
# we pass a list instead of multiple values
patient_obj = Patient(patient_data) 

You’d want to adjust the __init__ definition to take a single list instead of several values. You’d then when want to assign the elements of the list to the relevant attributes, .name, .age and so on within the method definition.

1 Like