8/13


#1

So I have no idea whats going on.
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]

my output
orange
prices 1.5
stock 32
pear
prices 3
stock 15
banana
prices 4
stock 6
apple
prices 2
stock 0

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


#2

So i clicked get code and the correct code was

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

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

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

the only difference is the format of the dictionary


#3

does this (your code):

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

look the same as this (correct code):

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

In the correct code i see a price label, in your code i see prices

in the correct code i also see colons as part of the label, not in your code

the exercise mentions the output needs to be an exact (aka perfect) match. The dictionaries is not what you should focus on


#4

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