Shopping list reporting invalid syntax


#1

I’m working on the Making a Purchase exercise but am getting a syntax error on my total additions.

I don’t want to look at the solution since I want to learn but it looks right to me. I am trying to add to the current total not overwrite it.

shopping_list = ["banana", "orange", "apple"]

stock = {
  "banana": 6,
  "apple": 0,
  "orange": 32,
  "pear": 15
}
    
prices = {
  "banana": 4,
  "apple": 2,
  "orange": 1.5,
  "pear": 3
}

# Write your code below!
def compute_bill (food):
  total = 0
  for item in prices:
    	total = total += prices[item]
  return total

The error returned in the console is:

 File "python", line 21
    total = total += prices[item]
                   ^
SyntaxError: invalid syntax

#2

Fixed the syntax, realised I had two totals.

Now just gotta work out why it return 10.5 instead of 2!


#3

you loop over the prices dictionary, so your program just buys one product of each for every customer, regardless of what the customer actually wants to buy


#4

Ah!
Thank you.
:grinning: