Need help


#1



A Day at the Supermarket | Owning a Store | 9. Something of Value

The error message reads:

"Traceback (most recent call last):
File "python", line 23, in
TypeError: unsupported operand type(s) for +: 'int' and 'str'"

I get that you can't add an int and a str, but I don't get how I'm supposed to make them compatible.


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 price in prices:
    amount= "%s * %s" % (prices[key], stock[key])
print amount
new_total = total + amount
print new_total


#2

This variable is a string. We cannot add a string to a number.

Try using the previous loop to generate a total.

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

print total

None of the remaining lines is expected by the lesson checker.