Code 8: Keeping Track of the Produce


#1



Seems I have an issue with converted arguments? Code looks right, but get the same error with any changes I do. I suspect is has something to do with 1.5 v. 32 for oranges.

Here's the code:
'''
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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

for thing in prices:
print thing
print "price: %s" % prices[thing]
print "stock: $s" % stock[thing]

'''
and how come I put the code in with indentations here, but in the post it doesn't show indents? Corrected myself, see below. Doh!

Here's the error:
Traceback (most recent call last): File "python", line 18, in TypeError: not all arguments converted during string formatting

I've looked at other discussions and I see no difference in my code that what is expected. Either that or my eyes are crossed and I'm only seeing what I want to see!

Bill


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

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

for thing in prices:
    print thing
    print "price: %s" % prices[thing]
    print "stock: $s" % stock[thing]


#2

Found it! Eyes crossed $ instead of %. Typical typo that you find after doing a post on it!
Kicked myself twice now.

Thanks all!


#3

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