My code prints the item, price, and stock - why isn’t it accepted?

Funny, it worked for the previous poster. Try a reset then use the code and see what happens.

hello, I was struggling with this one for a while! But realised it prints in their specified format if you put commas at the end of the first two print statements :slight_smile:

1 Like

Still having trouble with this one. None of the following worked:

for item in prices:
  print item + " price: %s" % prices[item] + " stock: %s" % stock[item]
  
for item in prices:
  print "%s price: %s stock: %s" % (item, prices[item], stock[item])
  
for item in prices:
  print item
  print "price: %s" % prices[item]
  print "stock: %s \n" % stock[item]

Hah! Even if I select to get the solution and move on, I copied the entire solution text, then reset the exercise and pasted in the exact same solution … it still wouldn’t pass! BUG!

1 Like

Yes, verified! This exercise has been shown to be buggy in numerous posts on multiple threads. Let us hope that the fact that no one has bothered to fix it is evidence that CA is letting the concept of Python 2 as appropriate instruction for beginning coders die the quiet (and, one hopes, quick) death it deserves.

Come on, CA Czars, the stable release will be 3.8 by the end of the year!

1 Like

My code was

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

which is of course a better solution than

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

because the exercise specifically tells you that the output has to be in this format:

apple price: 2 stock: 0

whereas the solution it spits out will have the format:

apple
price: 2
stock: 0

I know, I’m splitting hairs here, but it’s still not the same. I just can’t understand however why the checker is focused on the code I wrote instead of checking the output on the console.

In fact, the End-of-life date for Python 2.7 is 2020-01-01, according to the following chart from Status of Python branches:

Branch Schedule Status First release End-of-life Release manager
master PEP 596 features TBD TBD Łukasz Langa
3.8 PEP 569 prerelease 2019-10-21 2024-10 Łukasz Langa
3.7 PEP 537 bugfix 2018-06-27 2023-06-27 Ned Deily
2.7 PEP 373 bugfix 2010-07-03 2020-01-01 Benjamin Peterson
3.6 PEP 494 security 2016-12-23 2021-12-23 Ned Deily
3.5 PEP 478 security 2015-09-13 2020-09-13 Larry Hastings

Also see Python 2.7 will retire in….

Python%202%20Clock
Captured on June 10, 2019

It beggars belief why CA would have an available course with (known) unresolved bugs that hinders progress, in a veiled effort to endorse another (Python 3) course instead.
Surely you’re trolling?

The view that Python 2 no longer serves any purpose is largely subjective.

Nobody said Python 2 serves no purpose. It can certainly be used to teach all of the important concepts of procedural coding. But so can Python 3, so, given the choice, why select the version that is at its end of life? Unless a learner is planning to work for an enterprise whose software is coded in 2.7, I can see zero reason in 2019 to say, “Hmm, 2.7 or 3.x — I think I’ll go with 2.7!”

A better answer as to why this bug has not been fixed? People have been posting about it for months.

@mtf
I tried to reset then used the code you mentioned 6d ago…

for item in prices:
print item
print “stock: %s” % stock[item]
print “price: %s” % prices[item]

But, It also didn’t work…
I want to go next page…

But no answer has been posted, only guesses and heresay as to why it hasn’t been fixed. Hence my reason to post my query to the topic.

1 Like

My point exactly. Enterprise and mission-critical software in LTS, including the financial, educational ans medical sectors, which I know many companies working on contracts for (including mine) and have to be python 2.7 compliant to support existing APIs until migration can occur.

1 Like

Even the solution, provided is not working

There are an ss and the link of my code. Why is CA not accepting my answer? I clicked to see the answer and the only difference I can spot is the name of my variable on my statement, it goes from fruits to food.

Help please, no errors from the console so it has to be the website.

As you can tell if you read the thread, this bug has been reported numerous times, with zero response from CodeAcademy.
I think that the Python 2 course is the Windows 95 of Code Academy.

Or, depending upon generation, Vista or Windows 8.

I loved Windows 98, XP and Windows 7, which I still use.

1 Like

I dont understand, I had test 3 way with a good result but nothing work for the validate service:

for key in prices :
print “%s price: %s stock: %s” %(key, prices[key], stock[key])

print “%s” %key
print “price: %s” %prices[key]
print “stock: %s” %stock[key]

print “%s \nprice: %s \nstock: %s\n” %(key, prices[key], stock[key])

and my result is (for the first exemple):

orange price: 1.5 stock: 32
pear price: 3 stock: 15
banana price: 4 stock: 6
apple price: 2 stock: 0

I had verify is the same format than the exemple.

This has been reported several times. Unfortunately, there are 2 issues with this exercise.

The first issue is that the output that is shown as an example is not formatted correctly. The correct output format is actually like this, where you are expected to use print 3 times:

orange
price: 1.5
stock: 32

The second problem is that there is no way to pass the validation without pressing the Solution button, so press the Solution button when it becomes enabled, then click Run to pass the validation.

Been sitting with it for 20 minutes but I can’t solve it. I printed the answer EXACTLY like they wanted it too. Any ideas? !