0
0
Pythonprogramming~10 mins

Why functions 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 named greet.

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

Complete the code to call the function greet.

Python
def greet():
    print("Hello!")

greet[1]
Drag options to blanks, or click blank then click option'
A(None)
B[]
C()
D{}
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting parentheses when calling a function.
3fill in blank
hard

Fix the error in the function definition to print a message.

Python
def greet[1]:
    print("Hello!")
Drag options to blanks, or click blank then click option'
A(void)
B{}
C[]
D()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Leaving out parentheses in function definitions.
4fill in blank
hard

Fill both blanks to create a function that prints a message twice.

Python
def repeat_message():
    for _ in [1](2):
        print([2])
Drag options to blanks, or click blank then click option'
Arange
B"Hello!"
C2
Dprint
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a number instead of a range for looping.
Printing a function instead of a string.
5fill in blank
hard

Fill all three blanks to create a function that adds two numbers and returns the result.

Python
def add_numbers([1], [2]):
    result = [1] + [2]
    return result
Drag options to blanks, or click blank then click option'
Aa
Bb
Cresult
Dsum
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the same name for parameters and result variable.
Forgetting to return the result.