Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet.
Intro to Computing
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 'greet'.
Forgetting to add parentheses after the function name.
✗ Incorrect
The function name should be greet to match the instruction.
2fill in blank
mediumComplete the code to call the function greet.
Intro to Computing
[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
print() instead of the function name.Forgetting the parentheses after the function name.
✗ Incorrect
To run the function, you write its name followed by parentheses: greet().
3fill in blank
hardFix the error in the function definition to accept a name parameter.
Intro to Computing
def greet([1]): print(f"Hello, {name}!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than 'name'.
Capitalizing the parameter name incorrectly.
✗ Incorrect
The parameter should be named name to match the variable used inside the function.
4fill in blank
hardFill both blanks to define and call a function that adds two numbers.
Intro to Computing
def add([1], [2]): return a + b result = add(3, 4)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names that don't match the return statement.
Using more or fewer parameters than needed.
✗ Incorrect
The function parameters should be a and b to match the addition inside the function.
5fill in blank
hardFill all three blanks to create a function that returns the square of a number and call it.
Intro to Computing
def square([1]): return [2] * [3] result = square(5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the parameter and return statement.
Using a variable name not defined as a parameter.
✗ Incorrect
The parameter and both operands in the return statement should be the same variable num to correctly calculate the square.