QUESTION IMAGE
Question
what will be printed when we run
print(mystery(-5))
numeric answer
type your response
def mystery(num):
if num < 1:
return 0
if num % 2 == 0:
return num + mystery(num-2)
else:
return mystery(num-1)
Step1: Analyze the input
We need to find the value of mystery(-5). First, check the first condition in the function mystery. The input num = -5 and the first condition is if num < 1:. Since \(-5 < 1\), we follow this branch.
Step2: Return the value
According to the function, when num < 1, it returns \(0\). So mystery(-5) will return \(0\).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
\(0\)