# ARTURO ISRAEL LOPEZ MOLINA
# Python Dictionaries: Medical Insurance Project.
# Diccionarios de Python: Proyecto de seguro médico.
#1
medical_costs = {}
#2
medical_costs['Marina'] = 6607.0
medical_costs['Vinay'] = 3225.0
#3
medical_costs.update({'Connie': 8886.0, 'Isaac': 16444.0, 'Valentina': 6420.0})
#4
print(medical_costs)
{'Marina': 6607.0, 'Vinay': 3225.0, 'Connie': 8886.0, 'Isaac': 16444.0, 'Valentina': 6420.0}
#5
medical_costs['Vinay'] = 3325.0
print(medical_costs)
{'Marina': 6607.0, 'Vinay': 3325.0, 'Connie': 8886.0, 'Isaac': 16444.0, 'Valentina': 6420.0}
#6
total_cost = 0
for cost in medical_costs.values():
total_cost += cost
#7
average_cost = total_cost/len(medical_costs)
print("Average Insurance Cost: " + str(average_cost))
Average Insurance Cost: 8336.4
#8
names = ["Marina", "Vinay", "Connie", "Isaac", "Valentina"]
ages = [27, 24, 43, 35, 52]
#9
zipped_ages = zip(names, ages)
#10
names_to_ages = {key: value for key, value in zipped_ages}
print(names_to_ages)
{'Marina': 27, 'Vinay': 24, 'Connie': 43, 'Isaac': 35, 'Valentina': 52}
#11
marina_age = names_to_ages.get("Marina", None)
print("Marina's age is " + str(marina_age))
Marina's age is 27
#12
medical_records = {}
#13
medical_records["Marina"] = {"Age": 27, "Sex": "Female", "BMI": 31.1, "Children": 2, "Smoker": "Non-smoker", "Insurance_cost": 6607.0}
#14
medical_records["Vinay"] = {"Age": 24, "Sex": "Male", "BMI": 26.9, "Children": 0, "Smoker": "Non-smoker", "Insurance_cost": 3225.0}
medical_records["Connie"] = {"Age": 43, "Sex": "Female", "BMI": 25.3, "Children": 3, "Smoker": "Non-smoker", "Insurance_cost": 8886.0}
medical_records["Isaac"] = {"Age": 35, "Sex": "Male", "BMI": 20.6, "Children": 4, "Smoker": "Smoker", "Insurance_cost": 16444.0}
medical_records["Valentina"] = {"Age": 52, "Sex": "Female", "BMI": 18.7, "Children": 1, "Smoker": "Non-smoker", "Insurance_cost": 6420.0}
#15
print(medical_records)
{'Marina': {'Age': 27, 'Sex': 'Female', 'BMI': 31.1, 'Children': 2, 'Smoker': 'Non-smoker', 'Insurance_cost': 6607.0}, 'Vinay': {'Age': 24, 'Sex': 'Male', 'BMI': 26.9, 'Children': 0, 'Smoker': 'Non-smoker', 'Insurance_cost': 3225.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}}
#16
medical_records["Isaac"]["BMI"]
print("Connie's insurance cost is " + str(medical_records["Connie"]["Insurance_cost"]) + " dollars.")
Connie's insurance cost is 8886.0 dollars.
#17
medical_records.pop('Vinay')
#18
for name, record in medical_records.items():
print(name + " is a " + str(record["Age"]) + \
" year old " + record["Sex"] + " " + record["Smoker"] \
+ " with a BMI of " + str(record["BMI"]) + \
" and insurance cost of " + str(record["Insurance_cost"]))
Marina is a 27 year old Female Non-smoker with a BMI of 31.1 and insurance cost of 6607.0
Connie is a 43 year old Female Non-smoker with a BMI of 25.3 and insurance cost of 8886.0
Isaac is a 35 year old Male Smoker with a BMI of 20.6 and insurance cost of 16444.0
Valentina is a 52 year old Female Non-smoker with a BMI of 18.7 and insurance cost of 6420.0
#19 Final...