0
0
Pythonprogramming~10 mins

Positional arguments in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to call the function with two positional arguments.

Python
def greet(name, age):
    print(f"Hello {name}, you are {age} years old.")

greet([1])
Drag options to blanks, or click blank then click option'
A"Alice", 30
B"Bob", 25
C"Charlie", 20
D"Diana", 22
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing only one argument.
Forgetting the comma between arguments.
Using keyword arguments instead of positional.
2fill in blank
medium

Complete the function call to print the sum of two numbers using positional arguments.

Python
def add(a, b):
    return a + b

result = add([1])
print(result)
Drag options to blanks, or click blank then click option'
A5, 7
B5
Ca, b
D5 + 7
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing only one argument.
Passing an expression instead of two separate arguments.
Using variable names not defined.
3fill in blank
hard

Fix the error in the function call by completing the positional arguments.

Python
def multiply(x, y):
    return x * y

result = multiply([1])
print(result)
Drag options to blanks, or click blank then click option'
A4, 5
B4
Cx, y
D4 * 5
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing only one argument causes a TypeError.
Passing an expression instead of two arguments.
Using undefined variable names.
4fill in blank
hard

Fill both blanks to create a function call with three positional arguments.

Python
def describe_pet(name, animal_type, age):
    print(f"{name} is a {age} year old {animal_type}.")

describe_pet([1], [2], 5)
Drag options to blanks, or click blank then click option'
A"Buddy"
B"cat"
C"dog"
D"Max"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Swapping the order of name and animal type.
Using numbers instead of strings for name or animal type.
Missing quotes around string arguments.
5fill in blank
hard

Fill all three blanks to call the function with correct positional arguments.

Python
def book_info(title, author, year):
    print(f"{title} by {author}, published in {year}.")

book_info([1], [2], [3])
Drag options to blanks, or click blank then click option'
A"1984"
B"George Orwell"
C1949
D"Animal Farm"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Mixing up the order of arguments.
Using quotes around the year (should be a number).
Passing only two arguments instead of three.