8.Keeping track


#1

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]

what's wrong?


#2

Please post a link to the lesson as well as the error you're receiving.


#3

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


#4

you have a space after %s, remove it (from both), the printout should be an exact match


#5

Remove the space from after %s

Answered by @stetim94 in answer 4.


#6

Hi Guys,
i have following Error :
" Oops, try again. Check what your code prints for orange. It doesn't look quite right! "

Here's my code :

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

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

key=0

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

Any Solutions ? It shows the right solution but error is coming .... :frowning: thx !


#7

don't include a new line character (\n)

this is python 2, no need to use parentheses for print


#8

Thanks ! "\n" was the Problem ....


#9