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
intermediate2: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)
Attempts:
2 left
💡 Hint
Think about what the method returns when given 5.
✗ Incorrect
The method multiplies the input by 2 and returns it. So 5 * 2 = 10.
❓ Predict Output
intermediate2: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))
Attempts:
2 left
💡 Hint
Check if 4 is divisible by 2.
✗ Incorrect
4 is even, so the method returns True.
❓ Predict Output
advanced2: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))
Attempts:
2 left
💡 Hint
Factorial of 4 is 4 * 3 * 2 * 1.
✗ Incorrect
The factorial of 4 is 24 because 4 * 3 * 2 * 1 = 24.
❓ Predict Output
advanced2: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')
Attempts:
2 left
💡 Hint
Look at how the strings are joined with a space.
✗ Incorrect
The method returns the two strings joined by a space, so result is 'Hi There'.
❓ Predict Output
expert2: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'))
Attempts:
2 left
💡 Hint
Check which greeting is used when a keyword argument is passed.
✗ Incorrect
The keyword argument greeting='Hello' overrides the default 'Hi', so the output is 'Hello, Alice!'.