Something of value - Don't understand, please help!


How do you do it? I have this:

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 x in prices:
total = prices[x] * stock[x]
print total

But it says I'm not printing it correctly. Please help!


Does it also say in what way it isn't correct?
Things aren't just "wrong", there is some difference between the current state and what's considered correct. This difference says a great deal about what needs changing. So what's the difference?


Hi in the instruction they aske you to loop throught price and then made that operation
prices[x] * stock[x] and then add it to total so it should be like that

total = 0
for x in prices: 
    n = prices[x] * stock[x]
    total += n
    print total

I stored the a operation inside n and then added it to total


Thank-you for replies, I have got it now :slightly_smiling:


im sorry, i dont understand the total += n syntaxis, could you please explain it? thanks


HI you can do it like that

totale = totale + n
totale = totale + b

Its the same as..

totale += n
totale += b

Its another way to add.


ohhhhhh i get it now, thanks a lot!