A Day at the Supermarket - Keeping Track of the Produce


#1

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

Instructions:
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:

apple
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:
orange
prices: 1.5
stock: 32
pear
prices: 3
stock: 15
banana
prices: 4
stock: 6
apple
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]





#2

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


#3

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