0
0
Pythonprogramming~10 mins

Parameters and 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 define a function named greet that takes one parameter called name.

Python
def greet([1]):
    print(f"Hello, {name}!")
Drag options to blanks, or click blank then click option'
Amessage
Buser
Cname
Dgreeting
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different parameter name than the one used inside the function.
Forgetting to put a parameter inside the parentheses.
2fill in blank
medium

Complete the code to call the function greet with the argument 'Alice'.

Python
greet([1])
Drag options to blanks, or click blank then click option'
A"Alice"
BAlice
Cname
D'name'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the argument without quotes, which causes a NameError.
Passing the parameter name instead of the actual argument.
3fill in blank
hard

Fix the error in the function definition by completing the parameter list correctly.

Python
def add_numbers([1]):
    return a + b
Drag options to blanks, or click blank then click option'
Aa b
Ba, b
Ca; b
Da+b
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using spaces or other symbols instead of commas between parameters.
Writing parameters without any separator.
4fill in blank
hard

Fill both blanks to create a function that returns the product of two numbers x and y.

Python
def multiply([1], [2]):
    return x * y
Drag options to blanks, or click blank then click option'
Ax
By
Ca
Db
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different parameter names than those used in the return statement.
Mixing up the order of parameters.
5fill in blank
hard

Complete the code to create a function that returns a dictionary with keys as uppercase names and values as ages greater than 18.

Python
def filter_adults(data):
    return {name.upper(): age for name, age in data.items() if age [1] 18}
Drag options to blanks, or click blank then click option'
A{
B>
C<
D[
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets instead of curly braces for dictionary comprehension.
Using the wrong comparison operator in the condition.