A day at the supermarket


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096

Traceback (most recent call last):
File "python", line 14, in
NameError: name 'once' is not defined


Replace this line with your code. 
prices = {
    "banana": 4,
    "apple" : 2,
    "orange": 1.5,
    "pear" :3
    }
stock = {
    "banana": 6,
    "apple": 0, 
    "orange" :32,
    "pear" : 15
    }
for key in prices:
    print "prices: %s" % once[key]
    print "stock: %s" % twice[key]
    
Furthermore, can some explain to me what the %s is doing (the last two lines of code) Thanks.


#2

Oops I replaced once and twice with prices and stock on the last two lines
Made some progress I think


#3

It says i should have three print statements now


#4

you should also print the key (just the key)(see instructions)

%s is a placeholder for a string variable, so prices[key] gets at the place of the %s


#5

Revised code:

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 "prices: %s" % prices[key]
print "stock: %s" % stock[key]

Error messageOops, try again. Check what your code prints for orange. It doesn't look quite right!
:s


#6

this code:

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

print "prices:, if you look at the wanted output, you see price (without s), make sure it is an exact match to the wanted example


#7

Did you figure this out? I have this same problem. Something with a float?


#8

not, it has nothing to do with float, did you check your output was an exact match? If you need help, post your code so we can help you.


#9

I got the same "error". My code executed with no syntax errors and delivered the essential output. I think it is a silly reason to halt progress on the course. If I come across a similar message during this course, I going to abandon.


#10

Or you can just make a new topic with a quality question so someone can help you, programming is a struggle from time to time


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.