Why isn't this working?

<!DOCTYPE html>
    <!Hopefully this is better:->

(1) shopping_list = ["banana", "orange", "apple"]

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

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
def compute_bill(food):
total = 0
for item in food:
total += itemprices(map) return total


You can only return why inside a function (with proper indentation, remember!). The error is pointing out the you're trying to return a value without being in a function.


Hi, @quadrin ,

There is more than one mistake in your code. You have this where there should be a function header ...


That may be why the return statement is considered to be outside a function. Review the syntax of Functions, and correct the function header.

Also note that you need to be totaling up the prices of items. You have this ...

total += item

You need to use item to access the prices dictionary in the above.


@toplearner, thanks for mentioning indentation. @quadrin , our not being able to see your indentation makes it difficult for us to be sure we found all the bugs in your code. Formatting your code when you post it would enable users to see your indentation, underscores, and other important details.

See How do I format code in my posts?.


I got it fixed. Thanks for the help


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