Keeping Track of the Produce


#1


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

it says orange prints wrong. Why?


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]


#2

The SCT can see that extra space and doesn't expect it, so rejects the answer.


#3

OK I see he had a space. I used "prices: %s" and it printed but said orange was wrong. Why does "price: %s" work when the dictionary name is prices?


#4

Because price: is a string literal, in the singular, which is what is displaying: One price prints at a time. The argument is prices, the data dictionary being queried. The two are only related in terms, not by any direct means.


#5

Hello, I have the same problem. I've tried prices and price. I still get the same error message.

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]


#6

My bad. I had Price and Stock capitalised in the print section. Changed it to small letters and it worked.


#7

It may seem arbitrary, but we must submit strings as expected by the lesson checker (SCT).

price   instead of, Price
stock   instead of, Stock

#8

I had the same issue as @sauce_warrior. It might be worth putting that information in as a warning into the lessons somewhere, because I had no idea that capitalization would impact the answer, and the error it sent back about "the value for orange not being correct" was a total red herring.


#10

This my codes, I wrote in lower letter about "price" and "stock", exclude extra space also. But still could not make it. There still reveal same warning with others :

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

Any advice to my codes ? many thanks :slight_smile:

prices ={
"banana": 4 ,
"apple" : 2 ,
"orange" :1.5,
"pear":3
}
stock={
"banana": 6,
"apple" : 0,
"orange" :32,
"pear":15
}

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


#11

The lesson checker is expecting a space after the colon.

"price: %s"
"stock: %s"

#12

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: %s' % prices[key])
print ('stock: %s' % stock[key])


#14

To repeat:

"price: %s"
"stock: %s"

#15