8.Keeping track of the Produce


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096


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]


#2

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)


#4

@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]


#5

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]

#6

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


#7

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