'return' outside function


For some reason, whenever I use return, it gives me an error! Please help me!


Can you post your code?


return sends information to the function without printing it. When you call that function, the computer sees it as the returned value once you have run the function. You need to print whatever you are trying to do rather than return it if it is outside of a function. If it is inside of a function, you need to indent it properly so that it is recognized as in the function.


shopping_list = ["banana", "orange", "apple"]

shopping_list = ["banana", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3

Write your code below!

def compute_bill(food):
total =0

def compute_bill(food):
total = 0
for x in food:
total += prices[x]
return total
def compute_bill(food):
for i in food:
if stock[i]>0:
print total