Why it wont let me use Return


#1

At the end I used return total = ..... and it wont let me.
When I deleted it worked.

So why can't I use return? From what I know return is used to return the value for further use.

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

print total

#2

where is your function? Return is used in functions, you can't use it in a for loop (well, unless the loop is inside a function)


#3

Thank you - I always forget those little things and it drives me crazy!