here is my code.
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):
for items in shopping_list:
total= total + prices[key]
return total
the error states File “python”, line 22
SyntaxError: ‘return’ outside function
any tips anyone?


SyntaxError: ‘return’ outside function

return only makes sense inside function. so make sure the return statement is inside of that function.
check the indentation

and here

total= total + prices[key]

where does key come from?


ive tried the indentation a lot and it hasnt worked. but should i try prices[items]


to show the indentation here do the following

  • select the whole code
  • click on the </> above

you can edit your topic

yes ,you should :slight_smile: because you used items as a placeholder for the loop to go through the elements of the shopping_list


when i select it and click the buttons it replaces the code with the symbols. Do i have to do something else with them?


Have a look at this topic


I still don’t understand. I tried the back ticks and it said that the prices dictionary appears to be missing.
and i tried indenting and it said indenting error so i brought it back but then it gave me the same error.


def compute_bill(food):
total = 0
for ab in food:
total = total + prices[ab]
return total
bro use this one code. This will do it.


i got it before but thank you for helping though.


Do have any questions now?


I try that code but it does not work
the result is wrong
any suggestion?


did you indent? just send us the code and the error please


The program is worked, seems like the problem in the indent
Thanks for the code so i can pass this level


did you keep the space before return? Try doing that.


The problem already fixed


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.