Why isn't this code working?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096

I’ve written the code exactly the way it’s been written in the example given in the instructions but for some odd reason in the console box, instead of being printed once, the name, price and stock keep on repeating over and over again, although there are no error messages.

Please tell me what it is that I am doing wrong in this.

```python

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 “prices: %s” %prices[‘apple’]
print “stock: %s” %stock[‘apple’]

<do not remove the three backticks above>

#2

Instruction:

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

you are not told to print apple every time. The format should be look like that.
Instead of printing apple every time print the key.
remember the format should be exact match.


#3

I just did that, it’s still not working :frowning:


#4

can i see the update version of your code?

is it the same format what the instruction wants form you ?


#5

Oh nevermind, it worked. Thankyou so much :slight_smile:


#6

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