What is the problem in the output of this code?


#1

dictionary named prices

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

#dictionary stock

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

#print output in the formate as specified
"""apple
   price: 2
   stock: 0
 """
for key in prices:
    print key
    print "price: "+str(prices[key])
    print "stock: "+str(stock[key])+"\n"

#2

this exercise is very annoying, here:

#print output in the formate as specified

you have a print word. Which is what causes the error. remove print from that comment


#3

After removing that print word there still an error in my code
Would u plz help me to remove it


#4

can i see an updated version of your code?


#5

#dictionary named prices

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

#dictionary stock

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

#output in the formate as specified
"""apple
   price: 2
   stock: 0
 """
for key in prices:
    print key
    print "price: "+str(prices[key])
    print "stock: "+str(stock[key])+"\n"

#6

the +"\n" causes the output not to be exact match, please remove it


#8

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