Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 10, 2020 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/b8a3edd1c1bb6b12ca3bb4aa110ee4f1 to your computer and use it in GitHub Desktop.
Save codecademydev/b8a3edd1c1bb6b12ca3bb4aa110ee4f1 to your computer and use it in GitHub Desktop.
Codecademy export
medical_data = \
"""Marina Allison ,27 , 31.1 ,
#7010.0 ;Markus Valdez , 30,
22.4, #4050.0 ;Connie Ballard ,43
, 25.3 , #12060.0 ;Darnell Weber
, 35 , 20.6 , #7500.0;
Sylvie Charles ,22, 22.1
,#3022.0 ; Vinay Padilla,24,
26.9 ,#4620.0 ;Meredith Santiago, 51 ,
29.3 ,#16330.0; Andre Mccarty,
19,22.7 , #2900.0 ;
Lorena Hodson ,65, 33.1 , #19370.0;
Isaac Vu ,34, 24.8, #7045.0"""
# Add your code here
updated_medical_data = medical_data.replace('#',' ')
num_records = 0
for records in updated_medical_data:
if records == '$':
num_records += 1
print("There are " + str(num_records) + " medical records in the data.")
medical_data_split = updated_medical_data.split(';')
medical_records = []
for records in medical_data_split:
medical_records.append(records.split(','))
medical_records_clean = []
for records in medical_records:
record_clean = []
for item in records:
record_clean.append(item.strip())
medical_records_clean.append(record_clean)
for records in medical_records_clean:
records[0] = records[0].upper()
names = []
ages = []
bmis = []
insurance_costs = []
for records in medical_records_clean:
names.append(records[0])
ages.append(records[1])
bmis.append(records[2])
insurance_costs.append(records[3])
total_bmi = 0
for bmi in bmis:
total_bmi += float(bmi)
average_bmi = total_bmi/len(bmis)
print('Average BMI: ' + str(average_bmi))
total_insurance = 0
for data in insurance_costs:
total_insurance += float(data)
avg_insurance = total_insurance/len(insurance_costs)
print('Average Insurance Cost: ' + str(avg_insurance))
print(medical_records_clean)
for records in medical_records_clean:
info ='{} is {} years old with a BMI of {} and an insurance cost of ${}.'
info = info.format(records[0],records[1],records[2],records[3])
print(info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment