Https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/keeping-track-of-the-produce-

So am i doing something wrong or is this lesson broken. Even if i copy and paste the guides “solution” it fails the lesson.

Their solution did not input the code it asked which was to format it like “item price: 5 stock: 5” which my code below does.

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

Not even when you get it to output the way it asks does it let you pass the lesson.

Try using three print statements in your loop so everything prints on separate lines.

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

That is what the solution suggests is correct (solution posted above). Although if you were to copy and paste that it actually fails the lesson.

Print the answer in EXACTLY the following format:

apple price: 2 stock: 0

Is taken from the lesson itself and that code does not present itself in that format. The code i wrote in the op does print it in that format but still fails you.

This issue has been reported to the Curriculum Team so will eventually get looked into. For now, just accept that your code is correct and get the solution so you can move on.

1 Like