8. Keeping Track of Produce


#1



8. Keeping Track of Produce


"Check what your code prints for orange. It doesn't look quite right!"


I expect it to work and not sure why it doesn't.


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

You need lowercase in the print parts of the for loop.

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

Messed me up as well.


#3

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]

my code is this ,but it shows -
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

i cant get it right.


#4

You put a space between the colon and the words price/stock.
This is what it should look like.
print "price: %s" % prices[key]
print "stock: %s" % stock[key]


#5

Here's what worked in my case:
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]


#6

Hey man try this
prices = {}
stock = {}
for key in prices:
print key
print "Prices: %s"%prices[key]
print "Stock: %s"%stock[key]
it worked :joy:


#7

This one doesn't work properly. I put in the correct code and I got the "orange doesn't look right" error. I tried it again with empty dictionaries and it worked! This section needs fixing.


#8

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