A Day at the Supermarket


For some reason it is saying that "orange is outputting incorrectly, but it is not.
error message is "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

my code is printing as follows
price: 1.5
stock: 32
price: 3
stock: 15
price: 4
stock: 6
price: 2
stock: 0

I expect to get a green complete sign, but for some reason am not. Curious how to fix my answer so that it doesn't say orange is outputting wrong. It appears to be outputting correctly..

prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3

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

for Item in prices:
    print Item
    print "price:", prices[Item]
    print "stock:", stock[Item]


Check if there is an example of print formatting in the lesson text, and follow that example.

Aside: It is probably a good idea to stick to convention when naming ordinary variables. They are not usually capitalized.


My code follows the print formatting it is asking for.

What do you mean by conventions? like x and y?


item instead of Item. This is not an error on your part, just a style guide thing.

print "price: %s" % prices[item]


the printing formatting used in the exercise is %s, you should use that. (see information in exercise)


Thank you that worked. I guess I wasnt understanding what the %s % was doing, but I think I do now.


Thanks for the tip. I see your logic and will start using lower cases except in strings n stuff.


In strings, common grammar is usually what applies. Capitalized first word in a sentence, proper names, and so on.


yea, it serves as placeholder (s is for string), you can read more about it here if you want :slight_smile:


This is actually a page I found when I was trying to figure out what it was. Now i'm curious of what the, "more powerful string formatting method" is, they were talking about in that thread. I'll find out soon enough!


the more powerful method is format, it is also in this stackoverflow question, there is even a webpage about this


Woah I like that. I feel like I could do a lot more with the .format. Can't wait to start messing around with it!


Yep, format is more powerful, have fun learning it :slight_smile: