0
0
Pythonprogramming~20 mins

Return values in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Return Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this function call?
Consider the following Python function. What will be printed when result = multiply_and_add(2, 3) is executed and then print(result) is called?
Python
def multiply_and_add(x, y):
    product = x * y
    sum_ = x + y
    return product + sum_

result = multiply_and_add(2, 3)
print(result)
A11
B10
C5
D6
Attempts:
2 left
๐Ÿ’ก Hint
Remember to add both the product and the sum of the two numbers.
โ“ Predict Output
intermediate
2:00remaining
What does this function return?
What is the output of the following code snippet?
Python
def check_even(num):
    if num % 2 == 0:
        return True
    else:
        return False

print(check_even(7))
AFalse
BTrue
CNone
D7
Attempts:
2 left
๐Ÿ’ก Hint
Check if 7 is divisible by 2 without remainder.
โ“ Predict Output
advanced
2:00remaining
What is the output of this recursive function?
What will be printed when the following code runs?
Python
def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n - 1)

print(factorial(4))
A0
B24
C10
D120
Attempts:
2 left
๐Ÿ’ก Hint
Factorial of 4 is 4 * 3 * 2 * 1.
โ“ Predict Output
advanced
2:00remaining
What is the value of x after this function call?
What is the value of x after running the code below?
Python
def add_to_list(lst, item):
    lst.append(item)
    return lst

my_list = [1, 2]
x = add_to_list(my_list, 3)
print(x)
ANone
B[1, 2]
C[3]
D[1, 2, 3]
Attempts:
2 left
๐Ÿ’ก Hint
The function appends an item to the list and returns it.
โ“ Predict Output
expert
2:00remaining
What is the output of this function with multiple return statements?
What will be printed when the following code runs?
Python
def test_return(x):
    if x > 0:
        return 'Positive'
    elif x == 0:
        return 'Zero'
    return 'Negative'

print(test_return(-5))
ANone
BZero
CNegative
DPositive
Attempts:
2 left
๐Ÿ’ก Hint
Check the conditions for x = -5.