0
0
Pythonprogramming~20 mins

Positional arguments in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Positional Arguments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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)
AHello Alice, you are 30 years old.
BHello 30, you are Alice years old.
CTypeError: greet() missing 1 required positional argument
DHello name, you are age years old.
Attempts:
2 left
๐Ÿ’ก Hint
Remember the order of positional arguments matters.
โ“ Predict Output
intermediate
2:00remaining
Function call with swapped positional arguments
What will this code print?
Python
def calculate(x, y):
    return x - y

print(calculate(5, 10))
A5
BTypeError
C-5
D15
Attempts:
2 left
๐Ÿ’ก Hint
Check the order of subtraction with given arguments.
โ“ Predict Output
advanced
2: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"))
AName: Bob, Age:
BName: Bob, Age: 25
CTypeError: missing required positional argument 'age'
DName: , Age: 25
Attempts:
2 left
๐Ÿ’ก Hint
Default values are used when arguments are not provided.
โ“ Predict Output
advanced
2:00remaining
Error from missing positional argument
What error does this code raise?
Python
def multiply(a, b):
    return a * b

result = multiply(4)
ATypeError: multiply() missing 1 required positional argument: 'b'
BTypeError: multiply() takes 1 positional argument but 2 were given
CNameError: name 'b' is not defined
D4
Attempts:
2 left
๐Ÿ’ก Hint
Check how many arguments the function expects and how many are given.
๐Ÿง  Conceptual
expert
2: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?
Afunc(3, 2, 1)
Bfunc(b=2, a=1, c=3)
Cfunc(1, c=3, 2)
Dfunc(1, 2, 3)
Attempts:
2 left
๐Ÿ’ก Hint
Positional arguments must be in the order of parameters.