A Day at the Supermarket - Keeping Track of the Produce


Hi, I am stuck on the exercise “Keeping Track of the Produce”, could some one help me please?

Loop through each key in prices.

Like the example above, for each key, print out the key along with its price and stock information. Print the answer in the following format:

price: 2
stock: 0
Like the example above, because you know that the prices and stock dictionary have the same keys, you can access the stock dictionary while you are looping through prices.

The error message I get:
Check what your code prints for orange. It doesn’t look quite right!

The interpreter when I press enter:
prices: 1.5
stock: 32
prices: 3
stock: 15
prices: 4
stock: 6
prices: 2
stock: 0

My code:

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 "prices: %s" % prices[key]
  print "stock: %s" % stock[key]


a product should have a price: label, not a prices: label


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