Help With TypeError: '>' not supported between instances of 'float' and 'list'

Hi all. Wondering if you can help me understand why I’m receiving this error in the ds-python-loops-project

Traceback (most recent call last):
File “script.py”, line 20, in
if insurance_cost > average_cost:
TypeError: ‘>’ not supported between instances of ‘float’ and ‘list’

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 actual_insurance_costs:
  total_cost += insurance_cost

average_cost = [total_cost / len(actual_insurance_costs)]

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.")

Bingo! There’s your list.

A simple error to make, and thankfully simple to fix. Nix the brackets.

4 Likes

Thank you @mtf!! Really appreciate it.

1 Like

You’re welcome. Glad to be an extra pair of eyes.

1 Like