Orange Error


#1



Exercise:
Keeping Track of the Produce


Error:
Check what your code prints for orange. It doesn't look quite right!


I've tried looking online for help, and I've tried various configurations of brackets (parentheses) but it still doesn't work!


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

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

for i in prices:
    print i
    print "prices: %s" % prices[i]
    print "stock: %s" % stock[i]


#2

Hello

The issue is in the this section -

for i in prices:
print i
print "prices: %s" % prices[i]
print "stock: %s" % stock[i]

The lesson has the following description -

In the above example, we create two dictionaries, once and twice, that have the same keys.
Because we know that they have the same keys, we can loop through one dictionary and print values from both once and twice. Look carefully at the example.

Hint - Notice that you are using the 'i' but it is not a key?

Hope that helps.


#3

I re-did the code and it works now


#4

It is easy to give someone the answer but you will not learn python that way. Through struggle and perseverance, you got the code to work. Congrats.


#5

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