Hi there, im a beginner in coding and decided to start with python.
i have a problem in a course in Python: Python Objects
i have a list with prices:
list = [’$1.21’, ‘$4.50’, ‘$1.20’, ‘$3.57’ etc. ]
because of the dollar sign “$” each element is a string. But now, i have to strip the dollar sign and convert the string to a float. Finally i have to add all prices into total_sales.
i write the code:
total_sales = 0
for price in sales:
total_sales += price
i got a ValueError:
ValueError: could not convert string to float: ‘$1.21’
So i dont understand why my code is wrong and “price” cannot strip the dollar sign with .strip("$").
It would be nice if someone can help me.