Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Passing only one argument.
Forgetting the comma between arguments.
Using keyword arguments instead of positional.
โ Incorrect
The function greet requires two positional arguments: name and age. Passing "Bob", 25 correctly provides both.
2fill in blank
mediumComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Passing only one argument.
Passing an expression instead of two separate arguments.
Using variable names not defined.
โ Incorrect
The add function requires two positional arguments. Passing 5, 7 correctly calls the function.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Passing only one argument causes a TypeError.
Passing an expression instead of two arguments.
Using undefined variable names.
โ Incorrect
The multiply function needs two positional arguments. Passing 4, 5 fixes the error.
4fill in blank
hardFill 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'
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.
โ Incorrect
The function call needs the pet's name and animal type as the first two positional arguments. "Buddy" and "dog" fit correctly.
5fill in blank
hardFill 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'
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.
โ Incorrect
The function requires title, author, and year as positional arguments. "1984", "George Orwell", and 1949 are correct.