Oranges problem


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

I've even tried to copy and paste working codes I found in other discussions and still get the same error. any help is appreciated!

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

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

for key in prices:
    if key == 'apple':
        print key
        print 'price: %s' % prices[key]
        print 'stock: %s' % stock[key]


I solved this by printing the stockname (in your case key) also I did an additional for loop inside the first for-loop. And inside that nested for loop, I would check whether the item in price and stock are the same. If they are I would print the price and the stock out.

Hope it helps.


what do you have this:

if key == 'apple':

if condition for? You need to print the product name, price and stock of all products. Remove the if condition


I have had a similar issue. I already removed the if condition and it is still showing up with the "check what your code prints for orange. It doesn't look quite right!"


the same thing happened when I removed the if


@will2sing, please make a new topic. Otherwise, this topic becomes a clutter

@netcoder17988, can i see an updated version of your code?


My 2 guesses:
1) Indentation is important in Python. Have you checked that in your code?
2) instead of :
print 'price: %s' % prices[key]
try this:
print "price: " +str(prices[key])


I had the same error. I went through, and made sure that all of my "price" entries said "price", not "prices" with an S. That fixed it for me.


Your 2nd option works.


I had this same issue. Thanks for the help.


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