Ensure function is defined before function call before beginning body of function
Determine parameter values based on positional arguments, keyword arguments, and default values to initialize local variables
Use stack frame for function to trace local variables
At return to call site, pass values back to call site
Delete stack frame with local variables after return to call site
ExercisesExercises
1.
Q1: What is the output of the following code?
def foo(a, b):
if a > b:
return "a is larger!"
elif b > a:
return "b is larger!"
else:
return "a and b are equal!"
a = 10
b = 15
result = foo(b, a)
print(result)
"a is larger!"
"b is larger!"
"a and b are equal!"
Compiler error
2.
Q2: What is the output of the following code?
num = 10
a = double(5)
def double(num):
return num * 2
print(a)
5
10
20
Compiler error
3.
Q3: What is the output of the following code?
a = 10
def my_func(a, b, c):
c = c + 1
d = a * b + c
return d
c = 5
result = my_func(5, 2, 7)
print(result)
18
16
28
26
Compiler error
4.
Q4: What is the output of the following code?
def multiply(a, b):
return a * b
b = 3
def divide(a):
return a // b
first = 10
second = 5
multiply_result = multiply(first, second)
divide_result = divide(multiply_result)
print(divide_result)