0
0
Pythonprogramming~20 mins

Methods with return values in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Methods with Return Values
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 method call?
Consider the following Python code. What will be printed when result is printed?
Python
def multiply_by_two(x):
    return x * 2

result = multiply_by_two(5)
print(result)
A25
BTypeError
CNone
D10
Attempts:
2 left
💡 Hint
Think about what the method returns when given 5.
Predict Output
intermediate
2:00remaining
What does this method return?
Look at this method. What will print(check_even(4)) output?
Python
def check_even(num):
    if num % 2 == 0:
        return True
    else:
        return False

print(check_even(4))
AFalse
BTrue
CNone
DSyntaxError
Attempts:
2 left
💡 Hint
Check if 4 is divisible by 2.
Predict Output
advanced
2:30remaining
What is the output of this recursive method?
What will be printed when factorial(4) is called and printed?
Python
def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

print(factorial(4))
A24
B10
C0
DRecursionError
Attempts:
2 left
💡 Hint
Factorial of 4 is 4 * 3 * 2 * 1.
Predict Output
advanced
2:00remaining
What is the value of result after this method call?
Given this code, what will result hold after calling combine_strings('Hi', 'There')?
Python
def combine_strings(a, b):
    return a + ' ' + b

result = combine_strings('Hi', 'There')
A'Hi + There'
B'HiThere'
C'Hi There'
DTypeError
Attempts:
2 left
💡 Hint
Look at how the strings are joined with a space.
Predict Output
expert
2:30remaining
What is the output of this method with default and keyword arguments?
What will be printed when greet('Alice', greeting='Hello') is called?
Python
def greet(name, greeting='Hi'):
    return f"{greeting}, {name}!"

print(greet('Alice', greeting='Hello'))
A"Hello, Alice!"
B"Hi, Alice!"
C"Hello Alice"
DTypeError
Attempts:
2 left
💡 Hint
Check which greeting is used when a keyword argument is passed.