Python list and dictionary exercises


#1


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

Check what your code prints for orange. It doesn't look quite right!


I feel that the output is correct but still I am getting this error.


Replace this line with your 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 "price:%s" %prices[key]
    print "stock:%s" %stock[key]

this was the output:

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


#2

This exercise is very strict about formatting.

Your one of the o/p should look like this..

orange
price: 1.5
stock: 32

Can you find any difference(s) ?

hint**
spaces


#3

Thanks for the help. I tried doing that but it still gives me the same error!!!


#4

have you put spaces after colon ?


#5

here is my revised 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 "price: %s" %prices[key]
print "stock: %s\n" %stock[key]


#6

What newline character is doing there ?


#7

I put that to make it look systematic.


#8

Try erasing then submit the code?


#9

Ya it worked!! Thanks a lot!!!


#10

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