A Day at supermarket


#1

shows error: Oops, try again. It looks like your code did not print the correct total.

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:
prices[key] *= stock[key]
print prices[key]
total += prices[key]
print total


#2

total += prices[key]

its inverted
exchange it for:

prices[key] =+ total
print total


#3

This is correct. The assignment is always last in a compound operator.


#4

This expression needs assignment to the total as a product. You are modifying the prices which will really mess things up.

total += ___ * ___

#5

thanks sir, it really works


#7

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