prices and stock are dicts so you’re not going to want to multiply them. Get the relevant values and multiply those. If it’s a banana, then you’ll need to look up the price and stock for that, if it’s the whole stock then iterate through all keys of either dict.
@singha22
Sounds unlikely. Not saying Codecademy is in any way perfect, just that what you suggest isn’t something I’ve seen happen (I’ve been around a while, seen most ways things tend to go wrong).
print statements which say what’s being done step by step should let you sort that out.
Well I am a complete noob so i cant really answer. My advise would be to see what the total prints out when using total += prices[key] * stock[key] and try and see why the program is getting that total.
Again, total noob here that’s my way of debugging anyway
Hello, I would like to just say that there IS a small bug with lesson 8 and the code
for key in prices:
print key
print “price: %s” % prices[key]
print “stock: %s” % stock[key]
will not work for everyone as it didn’t for me. however some people seem to be able to get it right with the exact same code. Im using chrome, don’t know if that is maybe a source of the problem or maybe it is a problem with their internal servers. The code
total = 0
for key in prices:
print prices[key] * stock[key]
total = total + prices[key]*stock[key]
print total
is indeed correct (at least it works for me). Don’t know if this helps, just thought I’d make an effort to xD.
because the orange price is 1.5, %s will return a int so the orange will change to 1 and the answer is incorrect . Try %f ,the answer should be correct