10/13, can´t find the problem


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

It says that the return is outside the function and I don´t know how to get pass. Does anyone have any clever tip to help me?


#2

Well, I would delete the return because it is outside a function.

If you want to use return create a function if not delete it and assign a new variable then add to that variable.

Though because you are using a for loop at the top most level you should not have to do that, just delete your return and it should work fine.


#3

I removed the return but it says that my code didn´t print the right total, in which it does?


#4

solved it, thanks anyway


#5

Do you know how you fixed it?