Step 14 Question:
Instruction: Now, consider the list sales
. It is a list of strings that we want to sum. In order for us to sum these values, we will have to remove the $
, and set them equal to floats.
Iterate through sales
and for each item, strip off the $
, set it equal to a float, and add it to total_sales
I saw the solution but am trying to understand why my code isn’t working if performing each step individually. It provides an error message in the first iteration, it’s not stripping the “$”. This is the short version of the list. Thank you.
sales = [’$1.21’, ‘$7.29’, ‘$12.52’, ‘$5.13’, ‘$20.39’]
new_sales = 0
for sale in sales:
sale.strip(’$’)
float(sale)
new_sales += sale
print(new_sales)