8. Keeping Track of the Produce - not printing orange (using comma)


#1

On "8. Keeping Track of the Produce", I got the error "Oops, try again. Check what your code prints for orange. It doesn't look quite right!" when I was using comma to print the values. See the following code:

for key in prices:
    print key
    print "price: ", prices[key]
    print "stock: ", stock[key]

This was the result: https://monosnap.com/file/94bGbcOswXbVJmaqMYVf8dov0LEFR2 , though orange was printed, I still got the error.

I fixed it by transforming the float into str as in:

for key in prices:
    print key
    print "price: " + str(prices[key])
    print "stock: " + str(stock[key])

My question is: Why it didn't work with comma?


#2

it can work with the comma, but with the comma it creates an additional space, so this:

print "stock: " , stock[key]

means you have two spaces:

stock:__32

you only need one space, the checking script is strict in this exercise

You need just the one:

print "stock: ", stock[key]

#4

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