I don't get why I got it wrong?


#1

This is the code I wrote. It was obviously wrong? I don't get why I got it wrong?

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
    multiplier = prices[key] * stock[key]
    total = total + multiplier
    print total

9. Something of Value!
#2

Please post a link to this exercise so we can read the instructions and test your code. Thank you.


#4

most likely your "print total" statement under 'for loop' needs to be un-indented. You should print total outside of for loop. But as other person said, please paste the screen shot of error along with exercise description.


#5

Hi,

Thanks for the reply and sorry for my slow reply. For some reason I didn't get a notification. The reason there was no reference to the original exercise is because a mod split it from a longer thread.

This is the original exercise

and this is the result I found elsewhere on the forum

What I am finding is that I can work out roughly 50% of the exercises myself. The other 50% I am having to resort to finding the answers on the forums which is not the best for learning. I do try and work out the code even using pseudo-code on a scrap of paper.

I dont think im the best at this coding lark but I am keen to learn because its C21st literacy.

Thanks guys.