Python Lists project - medical insurance part 8

so far the project has gone smoothly until part 8. my code is exactly what the hint has and was working before part 8 and now im getting an error that doesnt make sense. please help. https://www.codecademy.com/paths/data-analyst/tracks/dsf-python-fundamentals-for-data-science-part-i/modules/dsf-python-lists/projects/ds-python-lists2-project

names = [“Mohamed”, “Sara”, “Xia”, “Paul”, “Valentina”, “Jide”, “Aaron”, “Emily”, “Nikita”, “Paul”]
insurance_costs = [13262.0, 4816.0, 6839.0, 5054.0, 14724.0, 5360.0, 7640.0, 6072.0, 2750.0, 12064.0]

Add your code here

names.append(“Priscilla”)
insurance_costs.append(“8320.0”)

medical_records = list(zip(insurance_costs, names))
print(medical_records)

num_medical_records = len(medical_records)
print(num_medical_records)

first_medical_record = medical_records[0]
print("Here is the first medical record: " + str(first_medical_record))

medical_records.sort()
print("Here are the medical records sorted by insurance cost: " + str(medical_records))

THIS IS THE ERROR:
Traceback (most recent call last):
File “script.py”, line 17, in
medical_records.sort()
TypeError: ‘<’ not supported between instances of ‘str’ and ‘float’

names = ["Mohamed", "Sara", "Xia", "Paul", "Valentina", "Jide", "Aaron", "Emily", "Nikita", "Paul"] insurance_costs = [13262.0, 4816.0, 6839.0, 5054.0, 14724.0, 5360.0, 7640.0, 6072.0, 2750.0, 12064.0] # Add your code here names.append("Priscilla") insurance_costs.append("8320.0") medical_records = list(zip(insurance_costs, names)) print(medical_records) num_medical_records = len(medical_records) print(num_medical_records) first_medical_record = medical_records[0] print("Here is the first medical record: " + str(first_medical_record)) medical_records.sort() print("Here are the medical records sorted by insurance cost: " + str(medical_records))

In line 6 of the Codebyte, you appended a string instead of a float.
Change

insurance_costs.append("8320.0")

to be

insurance_costs.append(8320.0)

so that you’re appending a float instead.

2 Likes

Oh that’s the problem! Thank you so much!! It’s been driving me crazy!