Another Orange Problem


#1

Having trouble with oranges, not sure of the issue.

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

What is causing the error with oranges and what is the purpose of the print value line? The correct orange values print, but the error suggests the code isn't quite right.


#3

Check the example in the lesson text.

"price: %s" % prices[value]

In your code, value is not really a meaningful name, since it is not a value, but a key name. Naming variables is skill one should work hard to develop so others can read your code and understand it.


#4

I am not really good at this but i had the same problem and it was fixed when i changed
print "Prices: %s" prices[value]
Instead of the line above i switched to
print "Price: %s" prices[value]
if its hard to see i switched "Prices: %s" to "Price: %s"
sorry if my English is not 2 good i hope you understand anyway


#5

I changed the variable name to key and still have a problem with orange, but the correct values for orange print. What am I missing?


#6

That's just the only error message available to the SCT, and not a problem with orange, per se. See the example in the lesson text.

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

#7

Hello,

Not sure if you are in codecademy, but I rewrote the code and still have the same orange issue. The correct values are displayed yet I get an error. This is the updated 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 "Price %s" % prices[key]
print "Stock %s" % stock[key]


#8

See above. Be sure to include the colon.


#9

I have rewritten code and still getting an error.


#10

Please post your formatted code, and a link to this lesson. Thanks.


#11

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3

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

#12

See the example in the instructions...

apple
price: 2
stock: 0

How would you get your output to look exactly like this?


#13

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

That code


#14

What does your output look like?


#15

orange
Price 1.5
Stock 32
pear
Price 3
Stock 15
banana
Price 4
Stock 6
apple
Price 2
Stock 0
None


#16

How is this different from the example? Look closely and make your output exactly the same as the example.


#17

oh my, I got and and cant believe I missed that. Thank You! May I ask what is being done with the print statements? What I mean is if I was telling someone step by step how Python knows to print each aspect.


#18

I guess a better question is, what causes the code to print the price with price and stock with stock?


#19

I am getting the same error too.


#20

copy/paste your code.


#21

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