8. Keeping Track of the Produce


#1

What's wrong with orange??? Do I need %f because price of orange is a decimal??

THANKS!


#4

Hi,

I had exactly the same issue.

The reason was a typo. Don't use capital letters in price and stock.

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

#5

this doesn't work. In the example in this section, they use capital letters Once and Twice, so that's why I did.


#6

this still doesn't work! It shouldn't matter anyway because on the previous exercises the instructions had me us " not '. This is getting kind of ridiculous. The code is perfectly correct.

Thanks


#7

So guys.....I literally just retyped the entire code verbatim and it decided to work. Pretty upset though. I quit last night much earlier than I wanted to because of this glitch...or whatever we'll call it. Thanks for the help, though.

ALSO: I think I forgot to jot this down in my notes in past sections, but could either of you or anybody else recollect me on the use of the " %s" % in this code. Thanks!!


#8

You can go back to any previous lesson. I often do this if I am having trouble with something. If I still cannot figure out my issues then I come to the forums to see if I can find a solution. Glad you got the issue worked out. Good luck.


#9

Don't even need to write it down. Google python string formatting, look for a hit on python.org. You'll have to scroll down somewhat.


#10

Ok, honestly I had to trawl around to find a solution to this. The instructions say to use the same coding they used in the example, but that didn't work for me no matter how many revisions I made.

Here's the solution I found:
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3
}

stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15
}

for k in prices:
print k
print "price: " + str(price[k])
print "stock: " + str(stock[k])

The end of the code is very different from the example. I'm losing my patience with this website. Might go back to "Automate the boring stuff with Python" to get my basics down.


#12

Yeah, I had the same error --->
print "Price: %s" % (prices[key]) #Note the capital P
print "Stock: %s" % (stock[key]) #Same Capital S

When changed to this I go the green light.
print "price: %s" % (prices[key])
print "stock: %s" % (stock[key])


#13

Don't forget your indexing after the
for key in prices:

That is what solved it for me.


#15

Thanks for the help! One question though, what function does the [key] part of prices[key] do?


#16

2 posts were split to a new topic: 8. Why do we need to print key under the for loop?


#17

The same thing happened to me with the same error & like you I reset and retyped the code and it worked.


#18

This worked! Thankyou :slightly_smiling:


#19

for key in prices:
print key
print "price: %s" %(prices[key])
print "stock: %s" %(stock[key])

Please note that there is a space between "price:" and %s


#20