Something of Value: A Day at the Supermarket


#1
  1. I keep getting this wrong and I don't understand what is wrong.
    Traceback (most recent call last):
    ** File "python", line 18, in **
    NameError: name 'total' is not defined
    <This is what the screen thing told me

  2. I am very confused why in "for key in prices" below that, we have to print key and then the weird % thing that I don't understand at all. Why couldn't I just put print prices and print stock. Like could you explain me the function of the %

  3. I don't get why the value += total does

I looked some of these up in the q&a thing and they said this was the answer but it doesn't seem to work

THANK YOOU


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

for key in prices:
    print key
    print "price: %s" % prices[key]
    print "stock: %s" % stock[key]
total == 0

for key in prices:
    value = prices[key] * stock[key] 
    print value
    value += total
    
print total


#2

total == 0                             # use assignment, not comparison

for key in prices:
    value = prices[key] * stock[key]   # change `value =` to `total +=`
    print value                        # remove this line
    value += total                     # remove this line

#4