move the total=0 out side the loop
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}
total = 0
for key in prices:
inventory = (prices[key] * stock[key])
print key
print "inventory value: %s" % (inventory)
total = total + inventory
print total
0
solved Python: adding results in for loop