0
0
Pythonprogramming~10 mins

Multiple parameters 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 that takes two parameters and returns their sum.

Python
def add_numbers(a, [1]):
    return a + b
Drag options to blanks, or click blank then click option'
Ab
Bc
Cx
Dy
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a parameter name that is not used in the function body.
Forgetting to add the second parameter.
2fill in blank
medium

Complete the code to call the function with two arguments 5 and 7.

Python
result = add_numbers([1], 7)
print(result)
Drag options to blanks, or click blank then click option'
A3
B5
C10
D7
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the wrong number as the first argument.
Passing only one argument.
3fill in blank
hard

Fix the error in the function definition to accept three parameters.

Python
def multiply_three(a, b, [1]):
    return a * b * c
Drag options to blanks, or click blank then click option'
Ac
Bd
Ce
Df
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a parameter name different from the variable in the return statement.
Forgetting to add the third parameter.
4fill in blank
hard

Fill both blanks to create a function that returns the average of two numbers.

Python
def average([1], [2]):
    return (x + y) / 2
Drag options to blanks, or click blank then click option'
Ax
By
Ca
Db
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parameter names that do not match the variables in the return statement.
Swapping the order of parameters incorrectly.
5fill in blank
hard

Fill all three blanks to create a function that returns a dictionary with keys as parameter names and values as their squares, only if the value is greater than 0.

Python
def squares_dict([1], [2], [3]):
    return {k: v**2 for k, v in zip(['a', 'b', 'c'], [[1], [2], [3]]) if v > 0}
Drag options to blanks, or click blank then click option'
Aa
Bb
Cc
Dd
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parameter names that do not match the keys in the dictionary.
Not matching the order of parameters and values in the zip function.