191 views

1 Answer

1 1 vote

The function keeps reducing the number using:

a = n // 10
b = n % 10
return mystery(a + b)

For $\texttt{mystery(678)}$:

n = 678
a = 678 // 10 = 67
b = 678 % 10 = 8
a + b = 75

So it becomes:

mystery(75)

Now:

n = 75
a = 75 // 10 = 7
b = 75 % 10 = 5
a + b = 12

So it becomes:

mystery(12)

Now:

n = 12
a = 12 // 10 = 1
b = 12 % 10 = 2
a + b = 3

So it becomes:

mystery(3)

Since $3 < 10$, the function returns $3$.

Therefore, the output is:

$3$

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
257
257 views
GO Classes asked Jun 30
257 views
Consider the following Python code:def total_first(t): if not t: return 0 return t[0][0] + total_first(t[1:]) data = [[2, 7], [5, 1], [3, 8], [4, 9]] print(total_first(da...
2 2 votes
1 1 answer
190
190 views
GO Classes asked Jun 30
190 views
Consider the following Python code:def count_greater(lst, v): if not lst: return 0 count = 1 if lst[0] v else 0 return count + count_greater(lst[1:], v) print(count_grea...
2 2 votes
1 1 answer
215
215 views
GO Classes asked Jun 30
215 views
Consider the following Python code:def show(lst, i=0): if i == len(lst): return show(lst, i + 1) if lst[i] % 2 != 0: print(lst[i], end="") show([1, 2, 3, 4, 5])What is th...
2 2 votes
1 1 answer
192
192 views
GO Classes asked Jun 30
192 views
Consider the following Python code:def solve(n): if n <= 0: return 0 return n + solve(n - 2) print(solve(6), solve(5))What is the output of the code above?9 1212 912 12Re...