8... Keeping track of produce "Check what your code prints for orange."


#1

I've read all the other topics on this and what prints is exactly what is expected to print.. I'm so clueless as to what is wrong here...


#2

I know that i can change the last two print lines to
print "price: " + str(prices[item])
print "stock: " + str(stock[item])

However in the instructions it tells me I can use the syntax from the example:

once = {'a': 1, 'b': 2}
twice = {'a': 2, 'b': 4}
for key in once:
print "Once: %s" % once[key]
print "Twice: %s" % twice[key]

I'm trying to understand why it fails when I use that syntax.


#3

For the string on line 5, you should have price singular instead of prices with an s.

The prices[key] bit should still have an s on prices, though.


#4

well dang it.... that is just stupid


#5

Can you re-post your updated code? Only the first part (the string) should have a singular price.


#6

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]

Works perfectly now....

Incorrect:

print "prices: %s" % prices[key]

Correct:
print "price: %s" % prices[key]


#7

Cool. Glad you got it working! Code on!


#8

Had the same error, and for me it was a capital.


#9

Literally for like 20 minutes I was like wtf then I checked this out and was like SERIOUSLY CAPITAL LETTER!!! lol


#10

I had exactly the same issue, however, my problem was that I wrote
"price: %s " instead of "price: %s"


#11

Those punctuation "errors" drive me freaking crazy! I have the habit of capitalizing the beginning of most words... I end up stuck on a lesson for a ridiculously long amount of time lmao.


#12

I know this conversation is old but I was recently using it - while the code now works why is it that "price: %s" % price[key] works. Why does the first "price" need to be singular?


#13

Having errors like this cost me 20 minutes of frustration is a bit annoying. Because I like to have proper capitalization on my output I am punished :frowning:


#14

that's actualy pathetic....


#16