Something of Values


#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

for key in prices:
total = total + prices[key] * stock[key]

print total

This is my code but I am not sure what I have done wrong!

It says when I enter it: Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: expected an indented block (python, line 22)

Please help!!


#2

this line:

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

should be in the body of the loop, to achieve this indent is required. You do it right on your previous loop (for key in prices)


#3

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