Lesson 9 Something of vaue. Stuck up .Pl help


#1

Below is my code.

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

print total

#2

All of the above lines need to be indented.

Aside:

The above does not need parens. Multiplication takes precedence to addition.

total = total + prices[key] * stock[key]

Since we're running a total, we can further simplify this with,

total += prices[key] * stock[key]

which adds and assigns in one step.