Something of Value [SyntaxError: 'return' outside function]


I don't understand why I get thrown this error, when trying to calculate the total value of the inventory:

SyntaxError: 'return' outside function

prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3,
stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15,

for item in prices:
    print item
    print "price: %s" % prices[item]
    print "stock: %s" % stock[item]

total = 0

for item in prices:
    total = prices[item] * stock[item]
    return total

print total


return can only exist inside a function:

return total

since you don't have a function, i suggest removing return.

also currently total gets assigned a new value, but it doesn't add it to total, it just overwrites total, think of a way to overcome this problem


Thanks man. I had complete missed the point about that return can only exist inside of a function. :smile_cat: