A Day at the Supermarket


#1




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
"
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
None
"


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]


#2

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.


#3

My code follows the print formatting it is asking for.
Item
Price
Stock

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


#4

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

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

#5

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


#7

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


#8

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


#9

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


#10

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


#11

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!


#12

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


#13

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!


#14

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


#17