0
0
Pythonprogramming~10 mins

Function definition and syntax 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.

Python
def [1]():
    print("Hello!")
Drag options to blanks, or click blank then click option'
Agreet
Bhello
Csay_hello
Dprint_greet
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different function name than 'greet'.
Forgetting the parentheses after the function name.
2fill in blank
medium

Complete the code to define a function that takes one parameter named name.

Python
def greet([1]):
    print(f"Hello, {name}!")
Drag options to blanks, or click blank then click option'
Aperson
Binput
Cuser
Dname
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different parameter name than 'name'.
Forgetting to include the parameter in parentheses.
3fill in blank
hard

Fix the error in the function definition by completing the code.

Python
def add_numbers(a, b[1]:
    return a + b
Drag options to blanks, or click blank then click option'
A,
B:
C)
D]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a colon instead of a closing parenthesis.
Leaving the parentheses unclosed.
4fill in blank
hard

Fill both blanks to define a function named multiply that returns the product of two parameters x and y.

Python
def [1]([2], y):
    return x * y
Drag options to blanks, or click blank then click option'
Amultiply
Bx
Cproduct
Dz
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different function name than 'multiply'.
Using a parameter name that does not match the return statement.
5fill in blank
hard

Fill all three blanks to define a function named is_even that returns True if a number n is even, otherwise False.

Python
def [1]([2]):
    if n [3] 2 == 0:
        return True
    else:
        return False
Drag options to blanks, or click blank then click option'
Ais_even
Bn
C%
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the wrong operator instead of modulo.
Using a different parameter name than 'n'.
Using a different function name.