Keeping Track of the Produce


#1



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

stock = {
    "banana": 6,
    "apple" : 0,
    "orange" : 32,
    "pear" : 15
}
for key in prices:
    print key
    print "price: ", prices[key]
    print "stock: ", stock[key]
    
__________
So its saying that the price for orange is not correct. I will attach screen shot of the error message. It seems to me that it is 100% right! confused. <img src="//codecademy-discourse.s3.amazonaws.com/original/5X/d/e/7/f/de7f2324775e4a634eb4d2e0aa88e8cbd11d7f49.PNG" width="689" height="464">


#2

I think the expected solution uses print formatting.

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

#3

Yep that was the issue. Kind of dumb but there it is! Thanks


#4

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

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

for key in prices:
print key
print "Price: %s" % prices[key]
print "stock: %s" % stock[key]

This is my code but still I am getting the same error , even though the values for orange is correct.
Kindly help!!


#5

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

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

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


  • You didn't leave a line after the curly bracket, I did.

  • You used double quotes, I used single quotes.

Hope this helps!


#6

You capitalized "P" in "Price". If you change it to lower case "p", it should work.


#7

Even if the print format they expect us to use is the %s, shouldn't doing
print "prices:", prices[key]
print "stock:", stock[key]
be correct anyways?

Here is my full code:
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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

for key in prices:
print key
print "prices:", prices[key]
print "stock:", stock[key]

and it's giving me this error: Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#8

It is correct code, but not what the author is expecting, given the example in the lesson text. In both this and your string format code will need a space after the colon, else the number is scrunched up to the text.


#9

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