A Day at the Supermarket (9/13)


#1

Please help me understand the individual stock * price numbers here. I've included my code and the output below. Codeacademy accepts the code and the total is correct but the printed values of each fruit's value seems odd. It said on an earlier lesson that you don't necessarily get the same order out of a dictionary each time but it always spits out the same results in the same order which seems to go orange, pear, banana apple.
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:
    print(prices[key] * stock[key])    
    total += (prices[key] * stock[key])

print total

orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
48.0
45
24
0
117.0
None

#2

you probably have problems with tabs.. I copied your code and it runs propertly..