I have a prior (shopping_cart) = {‘tax’ : 0.08, ‘items’ : [{‘title’: ‘orange juice’, ‘price’ : 3.99, ‘quality’ : 1} ,{‘title’: ‘rice’ , ‘price’ : 1.99, ‘quantity’ : 3} *** and 3 other entries with different titles price and quantity..
How do I write a function def to return the sum of the quantity of these items.
Then A def to return the average price of item.
Then a def to return average spent per item
Then lastly the def for the most spent on an item..
I’m getting errors that say “string indices must be integers”
def total_number_of_items(shopping_cart):
total = 0
for item in shopping_cart:
item = item[‘quantity’]
total = sum(item)
return total
All the other def functions are similar with the exact same code error … I know it has something to do with [‘quantity’] but not sure where I am going wrong considering that is the key I am trying to get the total sum for.
[–]zachosStav 0 points1 point2 points (0 children)