Shopping at the Market


#1

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

how can i print the total ?
I am getting this error message below
"Oops, try again. It looks like your code did not print the correct total."


#2

You are going to need a second for loop to get the total. The first for loop should take care of printing out the price and stock information. The second for loop should run

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

Then at the very end you can run print total.


#3

thanks mkordik.
It worked for me now


#4

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