Keeping Track of The Produce


#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 "%s" % key
    print "price %s: " % prices[key]
    print "stock %s: " % stock[key]

Whats Wrong with this ?


#2

the %s serves as placeholder, it will hold the variable, so the colon should be after price and before %s:

print "price: %s" % prices[key]

make sure you have no trailing spaces after %s, you also have to do this for stock


#3

Agreed. But then how come print "%s:%s:%s" %(var1,var2,var3) prints fine.
by the way i got your point thanks for the help. I will close the thread.


#4

oh no, not like that. It was just that your output didn't match with what was asked of the exercise because you placed the colon at the wrong place.

You can have a colon after %s, just not to pass this exercise

You will close the topic? That i need to see


#6

it is price instead of prices, but given you deleted your post i guess you figured that out


#7

it was a bad screenshot, my error message is Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#8


#9

okay, but my point still stand:

the output should be an exact match to what is asked in the instructions


#10

it works when I changed the prices to price


Keeping track of produce
#11