Oranges problem


#1



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


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]


#2

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.


#3

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


#4

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!"


#5

the same thing happened when I removed the if


#6

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

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


#7

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])


#8

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.


#9

Your 2nd option works.


#10

I had this same issue. Thanks for the help.


#11

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