Please help me: python, 8 keeping track of the procedure


#1

I have a question: I don’t know how to fix this. When I run the code I get this error: “Check what your code prints for orange. It doesn’t look quite right!”.

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

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

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

Thank you


#2

here:

print "apple"

you always print apple, even when the product is orange, pear or banana


#3

I don’t understand. What do I need to do precisely?


#4

Of each product you need to print:

the name
the price
the amount in stock

but when you print the name, you always print apples, but apples aren’t the only product you have in store. You should print the name of the product you want to display information on


#5

How do I only print the name?


#6

If you just want the solution, there should be such a button in the lesson after several failed submits.

We use a loop to get the different values from dictionary, but what value does the loop iterator (key) have? What are the values hold by the loop iterator?


#7

Made it, thanks!

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

#8