0
0
Pythonprogramming~20 mins

Multiple parameters in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Master of Multiple Parameters
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of function with multiple parameters and default values
What is the output of this Python code?
Python
def greet(name, greeting="Hello", punctuation="!"):
    return f"{greeting}, {name}{punctuation}"

result = greet("Alice", punctuation=".")
print(result)
AHello, Alice.
BHello, punctuation.
CHello, Alice!
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Check which parameters have default values and how they are overridden.
โ“ Predict Output
intermediate
2:00remaining
Output of function with *args and multiple parameters
What will this code print?
Python
def add_numbers(a, b, *args):
    total = a + b
    for num in args:
        total += num
    return total

print(add_numbers(1, 2, 3, 4))
A7
B6
CTypeError
D10
Attempts:
2 left
๐Ÿ’ก Hint
Remember *args collects extra positional arguments as a tuple.
โ“ Predict Output
advanced
2:00remaining
Output of function with keyword-only parameters
What is the output of this code?
Python
def describe_pet(name, *, species="dog", age=1):
    return f"{name} is a {age}-year-old {species}."

print(describe_pet("Buddy", species="cat"))
ABuddy is a 1-year-old cat.
BBuddy is a dog.
CTypeError
DBuddy is a cat.
Attempts:
2 left
๐Ÿ’ก Hint
Parameters after * must be passed as keywords.
โ“ Predict Output
advanced
2:00remaining
Output of function with multiple parameters and unpacking
What does this code print?
Python
def multiply(x, y, z):
    return x * y * z

values = (2, 3, 4)
print(multiply(*values))
A234
BTypeError
C24
D9
Attempts:
2 left
๐Ÿ’ก Hint
The * operator unpacks the tuple into separate arguments.
๐Ÿง  Conceptual
expert
3:00remaining
Understanding parameter passing with mutable default arguments
Consider this function definition: def append_item(item, items=[]): items.append(item) return items What will be the output of these two calls? print(append_item(1)) print(append_item(2))
A
[1]
[2]
B
[1]
[1, 2]
C
TypeError
TypeError
D
[1, 2]
[1, 2]
Attempts:
2 left
๐Ÿ’ก Hint
Default mutable arguments keep their state between calls.