I don't Know the syntax, stuck, need help, please!


10. A Day at the Supermarket

I don't know what syntax to use for getting the variable in a dictionary.

I need it to print the variable name, not the number or both.

price: 4
stock: 6

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

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

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


Sorry it's confusing, i need the syntax for the banana part.



you should print key (the loop iterator) which contains the individual items, not the prices dictionary


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