8.Keeping track of the Produce



Something is wrong with orange? Is it because it is not a float?

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]


the validition is really strict, you got the spacing around your colon wrong. it should be: price: %s, same goes for stock (that should go without saying)


@stetim94 I have a separate question:

If I want to use \n for this, how can I print the key and a string on the same line?

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


you won't be able to pass, but you would get:

for key in stock:
    print "%s\nprice: %s" % (key, prices[key])
    print "stock: %s" % stock[key]


@stetim94 you're right it's very strict validation, even the uppercase is wrong, you must write "price: %s" instean of "Price: %s"


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