Hello, I am attempting to complete the medical insurance project portion on strings:
https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-strings/projects/ds-python-strings-project
Here is my code:
updated_medical_data = medical_data.replace("#","$")
num_records = 0
for i in updated_medical_data:
if i == "$":
num_records += 1
print("There are {} medical records in the data".format(num_records))
medical_data_split = updated_medical_data.split(";")
medical_records = []
for i in medical_data_split:
medical_records.append(i.split(","))
# print(medical_records)
medical_records_clean = []
for record in medical_records:
record_clean = []
for item in record:
record_clean.append(item.strip())
medical_records_clean.append(record_clean)
print(medical_records_clean)
for record in medical_records_clean:
print(record[0].upper())
names =[]
ages = []
bmis = []
insurance_costs = []
for record in medical_records_clean:
names.append([record[0]])
ages.append([record[1]])
bmis.append([record[2]])
insurance_costs.append(record[3].replace('$',''))
print(names)
print(ages)
print(bmis)
print(insurance_costs)
total_bmi = 0
for bmi in bmis:
total_bmi += float(bmi)
This last portion of code is as suggested in the hint but yields an error:
Traceback (most recent call last):
File “script.py”, line 61, in
total_bmi += float(bmi)
TypeError: float() argument must be a string or a number, not ‘list’
Please help me figure out what in the world to do, this is rather frustrating that the hint led me into an error.