Whats wrong with my 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: %d" % prices[x]
    print "stock: %d" % stock[x]

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


me too, I got the same error information for my code...


So, I ran the code in the Python IDLE, and got the following output:

prices: 1
stock: 32
prices: 4
stock: 6
prices: 2
stock: 0
prices: 3
stock: 15

So the issue it's having is, it's saying that oranges cost $1.00 and not $1.50. I haven't done this particular exercise yet, so I'm not sure if you were shown to use them, but you could use %f instead of %d. For instance, %0.2f will print everything with 2 decimal places, so a 1 will be 1.00 and your oranges will come out to be 1.50. Hope this helps!


Okay, so I just did that program and went at it a slightly different way than you did.

prices = {"banana": 4, "apple": 2, "orange": 1.5, "pear": 3}
stock = {"banana": 6, "apple": 0, "orange": 32, "pear": 15}

for item in prices.keys():
print("price: " + str(prices[item]))
print("stock: " + str(stock[item]))


I ran into the same problem you did, except I used %.1f and %i. But apparently it wants %s for both.


change your code in printing section to
prices ------> price

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