Thread Shed bug?

I finished the Thread Shed project successfully, but was confused at step 14.

My code is as follows:

sales = ["$5.67", "$67.4", "$3.75"]
total_sales = 0
for i in sales:
  num = float(i.strip('$'))
  print(num)
  total_sales = total_sales + num
print(total_sales)

The exercise makes you iterate through a list of strings that need to be converted to floats and add it to total_sales. This code, for example, prints the clean floats and adds them to total_sales. But once you print total_sales, it prints “76.82000000000001”, which is a weird way of just saying “76.82”. It doesnt really affect my code in anyway, but my OCD is driving me nuts with this. Is there a way to solve this?

Hello, @too_toasty, and Happy Birthday!

You may not be familiar with this syntax, but try:

print('${:,.2f}'.format(total_sales))

You can read about it here: https://docs.python.org/3.3/library/string.html#module-string
You’ll have to scroll down a ways to find it.
Happy coding!

1 Like

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