Python Loops: Medical Insurance Project, stuck at one part, please help

Okay so I’m doing the “Python Loops: Medical Insurance Project” and I keep getting stuck at the same part, I’ve gone over my notes and even gone through the hints to make sure my code matches, still no luck.

Here’s my current code:

names = [“Judith”, “Abel”, “Tyson”, “Martha”, “Beverley”, “David”, “Anabel”]

estimated_insurance_costs = [1000.0, 2000.0, 3000.0, 4000.0, 5000.0, 6000.0, 7000.0]

actual_insurance_costs = [1100.0, 2200.0, 3300.0, 4400.0, 5500.0, 6600.0, 7700.0]

total_cost = 0

for insurance_cost in estimated_insurance_costs:

total_cost += insurance_cost

average_cost = [total_cost / len(actual_insurance_costs)]

print(“Average Insurance Cost: " + str(average_cost) + " dollars.”)

for i in range(len(names)):

name = names[i]

insurance_cost = actual_insurance_costs[i]

print("The insurance cost for " + name + “is " + str(insurance_cost) + " dollars.”)

if insurance_cost > average_cost:

print("The insurance cost for " + name + " is above average.")

elif insurance_cost < average_cost:

print("The insurance cost for " + name + " is below average.")

else:

print("The insurance cost for " + name + " is equal to the average.")

And this is the result I keep getting:

Average Insurance Cost: [4000.0] dollars.
The insurance cost for Judithis 1100.0 dollars.
Traceback (most recent call last):
File “script.py”, line 16, in
if insurance_cost > average_cost:
TypeError: ‘>’ not supported between instances of ‘float’ and ‘list’

I’m pulling my hair out over this, I know I’ve done something small.

As the error message tells us, your average_cost variable is actually a list containing one value, so the comparison between ‘float’ and ‘list’ is not going to work. I think you should make a small change to your code where you calculate the average cost.

1 Like

Well I found my mistake, I knew it was something silly,

average_cost = [total_cost / len(actual_insurance_costs)]

It was the square brackets, I suppose I was just going to quickly

1 Like

Happens to me too every day :blush: