What is the return value of mystery(4) ?
# python code start
def mystery(n):
answer = 0
while n > 0:
answer = answer + 1
n = n - 1
answer = answer - 2
return answer
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The while loop executes 4 times, for values n = [4, 3, 2, 1]. answer increases by 1 each time, so by the end of the loop, answer == 4 . Finally, subtract 2 from answer to give the final value: 2 .