Python Dictionaries: Medical Insurance Project Extra

Hi everyone!

I’m trying to do the extra task for the Python dictionaries: medical insurance project. T

Task:

  • Create a function called update_medical_records() that takes in the name of an individual as well as their medical data, and then updates the medical_records dictionary accordingly.

And that’s my answer:

medical_records["Filipa"] = {"Age": 35, "Sex": "Female", "BMI": 20.1, "Children": 1, "Smoker": "Non-smoker", "Insurance_cost": 6250.0}
medical_records["Dinis"] = {"Age": 35, "Sex": "Male", "BMI": 30.1, "Children": 1, "Smoker": "Non-smoker", "Insurance_cost": 5300.0}

def update_medical_records(medical_records):
  for record in medical_records:
    medical_records.update(medical_records)
  return medical_records 
  
medical_records = update_medical_records(medical_records)
print(medical_records)

Output:
{‘Marina’: {‘Age’: 27, ‘Sex’: ‘Female’, ‘BMI’: 31.1, ‘Children’: 2, ‘Smoker’: ‘Non-smoker’, ‘Insurance_cost’: 6607.0}, ‘Connie’: {‘Age’: 43, ‘Sex’: ‘Female’, ‘BMI’: 25.3, ‘Children’: 3, ‘Smoker’: ‘Non-smoker’, ‘Insurance_cost’: 8886.0}, ‘Isaac’: {‘Age’: 35, ‘Sex’: ‘Male’, ‘BMI’: 20.6, ‘Children’: 4, ‘Smoker’: ‘Smoker’, ‘Insurance_cost’: 16444.0}, ‘Valentina’: {‘Age’: 52, ‘Sex’: ‘Female’, ‘BMI’: 18.7, ‘Children’: 1, ‘Smoker’: ‘Non-smoker’, ‘Insurance_cost’: 6420.0}, ‘Filipa’: {‘Age’: 35, ‘Sex’: ‘Female’, ‘BMI’: 20.1, ‘Children’: 1, ‘Smoker’: ‘Non-smoker’, ‘Insurance_cost’: 6250.0}, ‘Dinis’: {‘Age’: 35, ‘Sex’: ‘Male’, ‘BMI’: 30.1, ‘Children’: 1, ‘Smoker’: ‘Non-smoker’, ‘Insurance_cost’: 5300.0}}

I’m not sure if this is what is being asked! If I create the records and then just print(medical_records, i get the same output. So not sure if answering it right

Thank you!

def update_medical_records(name, Age, Sex, BMI, Children, Smoker, Insurance_cost):
  record = {name : {"Age": Age, "Sex": Sex, "BMI": BMI, "Children": Children, "Smoker": Smoker, "Insurance_cost": Insurance_cost
  medical_records.update(record)
  return medical_records

Thank you so much! That’s what I’ve been thinking about, a generalized function.