0
0
Pythonprogramming~10 mins

Why different argument types are needed in Python - Test Your Understanding

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

Complete the code to define a function that takes one argument and prints it.

Python
def greet([1]):
    print(f"Hello, {name}!")
greet("Alice")
Drag options to blanks, or click blank then click option'
Aname
Bvalue
Cmsg
Dinput
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different parameter name than the one used inside the function causes a NameError.
2fill in blank
medium

Complete the code to define a function that adds two numbers and returns the result.

Python
def add_numbers(a, [1]):
    return a + b

result = add_numbers(3, 4)
print(result)
Drag options to blanks, or click blank then click option'
Ac
Bx
Cnum
Db
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a parameter name that does not match the variable in the return statement causes a NameError.
3fill in blank
hard

Fix the error in the function call by completing the argument type correctly.

Python
def repeat_text(text, times):
    return text * times

result = repeat_text("Hi", [1])
print(result)
Drag options to blanks, or click blank then click option'
A"3"
Btimes
C3
D'3'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the number as a string causes the function to repeat the string incorrectly or raise an error.
4fill in blank
hard

Fill both blanks to create a function that filters numbers greater than 5 from a list.

Python
def filter_numbers(numbers):
    return [num for num in numbers if num [1] [2]]

result = filter_numbers([2, 7, 4, 9])
print(result)
Drag options to blanks, or click blank then click option'
A>
B5
C<
D7
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' will filter numbers less than 5.
Using the wrong number in the comparison changes the filter result.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.

Python
words = ["apple", "cat", "banana", "dog"]
lengths = { [1]: [2] for word in words if len(word) [3] 3 }
print(lengths)
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
C>
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' changes the filter condition.
Swapping key and value causes incorrect dictionary structure.