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 item in prices:
print item
print"Price: %s" % prices[item]
print"Stock: %s" % stock[item]


Oops, try again.
Check what your code prints for orange. It doesn't look quite right!

I am keeping getting this error. Please help


Replace this line with your code.


#2

This is how I did it

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]


#3

it didnt work for me im getting the same error post as OP


#4

did u give space after print:?
i had made that mistake


#5

Hi,

try to insert some space under "for XXX in YYY" :

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

#6

copy your code in again so we can see what you have now.


#7

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

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

i'm getting the same error -

Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#8

i get this result after using the above code

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

still gives me an error


#9

This worked fine for me

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

i was using price and stock with capital P & S


#10

Hi All,

I've used the below 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: %s" % prices[key]
print "stock: %s" % stock[key]


gives the output as below

orange

prices: 1.5
stock: 32
pear
prices: 3
stock: 15
banana
prices: 4
stock: 6
apple
prices: 2
stock: 0
None


Error:

Oops, try again.
Check what your code prints for orange. It doesn't look quite right!

Please suggest what has gone wrong?


#11

Hey all! I've been getting the same error in this exercise/project.

https://gyazo.com/ac1b23c5c09db56669c394aac5b67943

If someone could help us all out, that would be great :smiley:

Here's my code, just in case.

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

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

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

EDIT: I found my problem, i forgot to put ":" (colons) in front of "price" and "stock" :wink:


#12

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

Change the "prices" to "price" as shown above. Hope this helps out!


#13

Hello, I'm getting the following error message as well:

"Oops, try again. Check what your code prints for orange. It does not look quite right!"

Here is my code:

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

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

for item in prices:
    print item
    print "Price: %s" % (prices[item])
    print "Stock: %s" % (stock[item])

#14

@the_architeqt

Remove the ()'s so that it will read...

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


#15

And lower case the Price and Stock in your code.


#16


#17


#18


#21

Any idea why we are getting this error? BTW I changed the starting letters of price and stock to small letters and the code worked.


#22

the solution they were looking for was case sensitive, hence the error; but if you were to test the code separately with capital P & S you would not have had any problem.