'return' outside function


#1

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


#2

Can you post your code?


#3

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.


#4

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):
total=0
for i in food:
if stock[i]>0:
total=total+prices[i]
stock[i]=stock[i]-1
print total