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


#1



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.
i.e.

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


#2

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


#3

here:

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


#4

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