Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet.
Python
def [1](): print("Hello!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a different function name than the one called later.
โ Incorrect
The function name must be greet to match the call.
2fill in blank
mediumComplete the code to call the function greet.
Python
def greet(): print("Hello!") greet[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Forgetting parentheses when calling a function.
โ Incorrect
Functions are called with parentheses () even if they have no inputs.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Leaving out parentheses in function definitions.
โ Incorrect
Function definitions require parentheses () after the name, even if no parameters.
4fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a number instead of a range for looping.
Printing a function instead of a string.
โ Incorrect
Use range(2) to repeat twice and print the message string.
5fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the same name for parameters and result variable.
Forgetting to return the result.
โ Incorrect
The function takes two inputs a and b, adds them, and stores in result.