0
0
Pythonprogramming~20 mins

Function call and execution flow in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Function Flow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of nested function calls
What is the output of this Python code?
Python
def f(x):
    return x * 2

def g(y):
    return f(y) + 3

print(g(4))
A7
B8
C11
D14
Attempts:
2 left
๐Ÿ’ก Hint
Remember to follow the order of function calls and operations step by step.
โ“ Predict Output
intermediate
2:00remaining
Value of variable after function call
What is the value of variable 'result' after running this code?
Python
def add_one(n):
    return n + 1

result = add_one(5)
A6
B5
CNone
DError
Attempts:
2 left
๐Ÿ’ก Hint
Check what the function returns and what is assigned to 'result'.
โ“ Predict Output
advanced
2:00remaining
Output with recursive function
What is the output of this recursive function call?
Python
def countdown(n):
    if n == 0:
        return 'Done'
    else:
        return str(n) + ' ' + countdown(n-1)

print(countdown(3))
AError
B"3 2 1 Done"
C"Done 3 2 1"
D"3 2 1 0 Done"
Attempts:
2 left
๐Ÿ’ก Hint
Trace the function calls from n=3 down to 0.
โ“ Predict Output
advanced
2:00remaining
Output with function modifying a list
What is printed after this code runs?
Python
def append_number(lst):
    lst.append(4)

numbers = [1, 2, 3]
append_number(numbers)
print(numbers)
A[1, 2, 3, 4]
B[4]
C[1, 2, 3]
DError
Attempts:
2 left
๐Ÿ’ก Hint
Think about how lists are passed to functions in Python.
โ“ Predict Output
expert
2:00remaining
Output of function with default and keyword arguments
What is the output of this code?
Python
def greet(name, greeting='Hello'):
    return f"{greeting}, {name}!"

print(greet('Alice'))
print(greet('Bob', greeting='Hi'))
A"Hi, Alice!\nHi, Bob!"
B"Hi, Alice!\nHello, Bob!"
C"Hello, Alice!\nHello, Bob!"
D"Hello, Alice!\nHi, Bob!"
Attempts:
2 left
๐Ÿ’ก Hint
Check which greeting is used for each call.