What does my code print for orange?


#1



Everytime I run this code, I get the error message, that "Check what your code prints for orange. It doesn't look quite right!"


When I get the results though, they appear just fine in the results window. In essence, it shows up as this:

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

So I'm not sure where the problem is orange is.


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

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

food = {
    "banana": "banana",
    "apple":"apple",
    "orange":"orange",
    "pear":"pear"}

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


#2

Link to the exersice, please


#4

Thank you.
As first, you don't need the "food" dictionary

Secondary:
It is otherwise right, but you should print "price: %s" instead of "Prices" and "stock: %s" instead of "Stock".

Remember to read the instructions well!


#5

try :
print "prices: %s" % prices[i]
print "stock: %s" % stock[i]
(All using lowcase)


#6

That line needs to be ...

print "price: %s" % prices[i]

Yes, you are correct about its needing to be all lowercase.


#7

Hello all.

I tried this out and here is my code:

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

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


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

error message is
Oops, try again.
You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)


#8

Just print i before your other print statements.


#9

yay it worked! thanks!


#10

No problemo. :slight_smile:


#11

the problem is with the blank spaces add them to the print statement


#13

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