# Showing error

#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 +=prices[item]
print (compute_bill(shopping_list))``````

``Replace this line with your code.``

#2

a function ends the moment a return keyword is reached

If the return keyword is reached in a loop, python will break the loop to end the function

#3

Oops, try again. compute_bill(['apple']) resulted in a RuntimeError: maximum recursion depth exceeded

``````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 +=prices[item]

print compute_bill(shopping_list)

#4

#5

a human needs sleep (at least, i do)

``print compute_bill(shopping_list)``

is inside your function, causing recursion (sort of like an infinity loop, but then with functions)

the function call execute the function, so place it outside/after the function to execute your function

Your loop still ends in the first iteration given a return keyword is reached

#6

sorry but not getting ya explain it some other time thx................

#7

What @stetim94 was trying to say is,

Your function call should be on a new indentation level,

Example:

``````def example_func():
return 'I am a function.'
print example_func() #function call is on a new indentation level outside of the function``````

and your return statement should be on the same indentation level as your for loop,

Example:

``````def example2(n)
for x in n:
x+=x[n]
return n #return statement is on the same indentaton level as for loop``````

#8

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