Why is this not working



Traceback (most recent call last):
File "python", line 22, in
TypeError: not enough arguments for format string

It should work and print the multiplied prices for each fruit and the overall totall

prices = {
    "banana" : 4,
    "apple"  : 2,
    "orange" : 1.5,
    "pear"   : 3,
stock = {
    "banana" : 6,
    "apple"  : 0,
    "orange" : 32,
    "pear"   : 15,

for key in prices:
    print key
    print "price: %s" % prices[key]
    print "stock: %s" % stock[key]
total = 0
for key in prices:
    price = prices[key] * stock[key]
    print "%s total = $%s" % key, price
    total =+ price

print "Total = $%s" % total

For print "%s total = $%s" % key, price it works if it is just print price but it doesnt do correct total


The %s character is a place holder for strings. You're trying to get a place holder for a numerical value, so you would need the %d for 'digit', or the %f for a floating point. I've made this mistake more times than I would like to admit.


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