8. 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 a in stock:
print a
print "price : %s" %prices[a]
print "stock: %s" %stock[a]
what is the problem?


#2

try:
print "price: %s" %prices[a]


#3

I'm having the same problem. It says my output for 'orange' has a problem. Can't figure it out.


#4

@l1palas @rubycoder49515 Try it this way, it should work:

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

#5

@frozentofu Thanks. I finally got it. @l1palas It was because I was printing Price and Stock instead of price and stock (lower case).


#6

"Check what your code prints for orange. It doesn't look quite right!"
this is the error i got
but th output seems pretty correct

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

please tell me whats the problem


#7

@cssrunner22312

Try typing Price and Stock with lowercase:

price:
stock:

just like in the instructions


#8

thanks
it worked
but what is the logic behind it?


#9

Your code was fine as it was before, but the codeacademy-editor checked if the code was written the way they wanted it (like in the instructions) , which was lowercased.


#10

thx :blush:
.................


#11

yw :grin:
glad if I could help


#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 "price:  %s" % prices[key]

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

keeps saying my value for orange is wrong


#13

Try it with one space between price: and %s and the same for stock: and %s

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]

10.8 Keeping track of the Produce
#14

thanks that worked but seriously just one space causing that problem geez "=_=


#15

me too, that is so strange, I checked my codes several times :sweat:


#16

I was printing prices instead of price


#17

Follow the examples in the instructions and it should work fine :slightly_smiling:


#18

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
for a in stock:
print a
print "price: %s" % prices[a]
print "stock: %s" % stock[a]


#19

thanks for that idea, my error was with white-space between price and colon
i wrote:
print fruit
print "price : %s" % prices[fruit]
print "stock : %s" % stock[fruit]
instead of
print fruit
print "price: %s" % prices[fruit]
print "stock: %s" % stock[fruit]
thanks for that reminder


#20

You're welcome :smiley: