Thread Shed step 14 float object not iterable error


I can’t figure out why receiving the following error at the task 14:

total_sales =
for sale in sales:
total_sales += float(sale.strip("$"))

Always throws this error:

Traceback (most recent call last):
File “”, line 143, in
total_sales += float(sale.strip("$"))
TypeError: ‘float’ object is not iterable

Any chance that sales is just a number instead of a list of numbers? The error message means that the variable type is not compatible with iterating in a loop. If sales were just one number, (i.e. type of float), the message might make sense.

This operator is used to extend a list. A float object is not a list so cannot be given as the extend value. It must be a list.

total_sales += [float(sale.strip("$"))]

But if you are shooting for a cumulative total, then start at zero.

total_sales = 0

Then your syntax is fine.

Gosh, I have set the total_sales variable as an empty list instead of 0. I haven’t figured it out from the error message.
Thank you very much for the help!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.