Challenge - 5 Problems
Positional Arguments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of function with positional arguments
What is the output of this Python code?
Python
def greet(name, age): return f"Hello {name}, you are {age} years old." result = greet("Alice", 30) print(result)
Attempts:
2 left
๐ก Hint
Remember the order of positional arguments matters.
โ Incorrect
The function greet takes two positional arguments: name and age. The call greet("Alice", 30) assigns name='Alice' and age=30, so the output is 'Hello Alice, you are 30 years old.'.
โ Predict Output
intermediate2:00remaining
Function call with swapped positional arguments
What will this code print?
Python
def calculate(x, y): return x - y print(calculate(5, 10))
Attempts:
2 left
๐ก Hint
Check the order of subtraction with given arguments.
โ Incorrect
The function subtracts y from x. With x=5 and y=10, the result is 5 - 10 = -5.
โ Predict Output
advanced2:00remaining
Positional arguments with default values
What is the output of this code?
Python
def info(name, age=25): return f"Name: {name}, Age: {age}" print(info("Bob"))
Attempts:
2 left
๐ก Hint
Default values are used when arguments are not provided.
โ Incorrect
The function info has a default value for age=25. Calling info("Bob") uses name='Bob' and age=25 by default.
โ Predict Output
advanced2:00remaining
Error from missing positional argument
What error does this code raise?
Python
def multiply(a, b): return a * b result = multiply(4)
Attempts:
2 left
๐ก Hint
Check how many arguments the function expects and how many are given.
โ Incorrect
The function multiply requires two positional arguments a and b. Calling multiply(4) provides only one argument, so Python raises a TypeError about the missing argument 'b'.
๐ง Conceptual
expert2:00remaining
Order of positional arguments in function call
Given the function definition
def func(a, b, c):, which call will assign a=1, b=2, and c=3 correctly?Attempts:
2 left
๐ก Hint
Positional arguments must be in the order of parameters.
โ Incorrect
Positional arguments are assigned in order: the first value to 'a', second to 'b', third to 'c'. Option D matches this order. Option D swaps values. Option D uses keyword arguments, not positional. Option D mixes positional and keyword incorrectly.