Lesson 8. Keeping Track of the Produce --- Check what your code prints for Orange


#1

I keep getting an error message stating the following:

**Opps try again. **
Check what your code prints for Orange
It does not look quite right!

However every prints out fine ?????????

prices = {
'Banana' : 4,
'Apple' : 2,
'Orange' : 1.50,
'Pear' : 3
}

dictionary called stock{}

stock = {
'Banana' : 6,
'Apple' : 0,
'Orange' : 32,
'Pear' : 15
}

def inventory_function(dictionary_1, dictionary_2):
for key_variable in dictionary_1 and dictionary_2:
print key_variable
print "Price: %.2f" % prices[key_variable]
print "Stock: %s" % stock[key_variable]

inventory_function(prices,stock)

Orange
Price: 1.50
Stock: 32
Pear
Price: 3.00
Stock: 15
Banana
Price: 4.00
Stock: 6
Apple
Price: 2.00
Stock: 0
None


#2

Have the same error.

If you have found any solution, please let me know.

Thank you!


#3

Hi here this part

def inventory_function(dictionary_1, dictionary_2):
for key_variable in dictionary_1 and dictionary_2:
print key_variable
print "Price: %.2f" % prices[key_variable] 
print "Stock: %s" % stock[key_variable]
inventory_function(prices,stock)

You could do its like that @stefan94

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

#4

I'm having the same issue here is my code

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

for key in sorted(prices.keys()):
print key
print "price: %s" % prices[key]
print "stock: %s \n" % stock[key]

Here is the console output:

apple
price: 2
stock: 0

banana
price: 4
stock: 6

orange
price: 1.5
stock: 32

pear
price: 3
stock: 15

None


#5

Hi try your for loop like that

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

#6

Hi,
I've the same error, but I have written the code exactly as you wizmarco proposed...


#7

HI @metsuke try to post your code with the error that you get.


#8

Thanks, here's 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]

And here the error:

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

... do you have an idea?


#9

Hi my print got a error too her how it should be

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

Just remove the uppercase P and S to Price and Stock


#10

Thanks it works... I don't understand why it doesn't the first time, because I'm sure I've tried without the uppercases... Never mind, it works now :slightly_smiling:


#11

Thank you

much appreciated


#12

Its still giving the same error:
Here is the edited 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]

And here is the console output:

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


#13

Hi @metalmount ount here

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

Just remove the uppercase P and S to Price and Stock