8/13 Keeping Track of the Produce: The Orange Glitch


#1

Hello. I have seen that many other people have been having the same problem as me. However, I am unsure of what to do. I have tried rewriting the code, I have tried changing the quotation marks to apostrophes, I have tried every solution I could find... has anyone else dealt with this before? a seemingly un fixable, glitchy section?

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

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

for x in prices:
print x
print "Prices: %s" % prices[key]
print "Stock: %s" % stock[key]

Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#2

you use the variable "key" instead of x in your for loop. What's happening is the program is looking for something in your list called "key" instead of your for variable x. It displays "check your orange" because orange is the first dictionary input that codecademy checks for in that lesson. Have a good one!


#3

Thank you Akruschwitz, but it is still doing the same thing. I enjoy your gracious help, but the new code:

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

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

for x in prices:
print x
print "Prices: %s" % prices[x]
print "Stock: %s" % stock[x]

still returns the same result:

Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#4

Check your capitals and stuff for the print script, I'm not certain how much wiggle room there is in the program! that's my best guess tho


#5

just found the answer, change the capitals in your string to "price: %s" and "stock: %s". it's just a formatting thing, the rest of your code is functional!


#6

I apologize, but I have tried that before... I have tried most every remedy I could find in the forums. I do not understand. in the console, whether those are capitals or not, it still comes up with the result. I know that the code works, and that it is printing the correct result. the red tab at the bottom however, will not allow me to continue...


#7

that happened to me too, i just reloaded the page and it worked fine. it was either that or I was missing a : somewhere, I don't really know. as long as your code works just skip it, in my eyes you're a winner :smiley:


#8

I had the same issue. The code is correct but it doesn't like the "s" in prices. Everywhere you have "prices" change to price. That worked for me.


#9

prices={"banana":4,"apple":2,"orange":1.5,"pear":3}
stock={"banana":6,"apple":0,"orange":32,"pear":15}
for element in prices:
print element
print"price:%s"%prices[element]
print"stock:%s"%stock[element]

I wrote this code but still result is same cant proceed without this:sweat: ......