A Day at the Supermarket: Something of Value


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]

for key in prices:

print total_m

I tried:
But it does not work.
But if I add a "_m" after the total, the result soon becomes valid?

What is the ideal answer to this questions?



total should be an integer, why is it a dictionary?



will re-assign total everytime, instead you should add prices[key]*stock[key] to what is already in total by doing:

total = total + ...


But I tried: total=total+prices["fruitname"]*stock["fruitname"].....
But the system said that I should not include the fruit names in the page.

Yeah I agree that the total should be an int, but I don't understand why the code above is valid for the question.


why did you change from key to fruitname?

i suspect its a corner case, sometimes invalid code slips through


Oh I just mean the meaning, not really "fruitname".
I typed "apple", "banana" and so on. And the system told me not to use fruits' names.
If I cannot type each fruit name after the prices and the stock, how can I add all the prices[key]*stock[key] together?


i already told you this?


Thank you, but I don't really understand what you mean...




will assign a value to total, but in doing so it will overwrite what is already stored in total. so we want to add prices[key]*stock[key] to what is already in total, we can achieve this by adding doing:

total = total + ...

simply mix total in the mix


Does the ... have special meanings?
do you mean: total = total + ...
or do you mean: total=total+prices[key]*stock[key]


woohoo, you understand :slight_smile:


hahaha, Thank you very much!