Questions for 8. Keeping Track of the Produce / 13


#1

If you don't want spoilers for the code, I suggest you stop reading right here. But you may go on....

This code works:

for key in prices:
    print key
    print 'price: %s' % prices[key]
    print 'stock: %s' % stock[key]

This one does too:

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

But not these two???

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

and

for key in prices:
    print '%s\nprice: %s\nstock: %s' % (key,prices[key],stock[key])

I'm aware that there are a lot of ways to do this part,
but why doesn't it accept the last two codes mentioned,
when in fact they all produce exactly the same result?
Is the section designed so that it prefers those first ones over these two?
Is this some way of encouraging students to adapt to some style/convention/rule?
If this is an issue, should it be fixed?
If not, then what is it?

All corrections and constructive criticisms are welcome. Thank you.


9.- How is Everybody doing?
#2

I actually ran into this issue as well. I tried doing

print 'price: ', prices[key]

and got the same result as you did. I ended up using

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

I think the reasoning was to force us to learn the alternate methods of string concatenation. That's my best guess anyway.