0
0
Pythonprogramming~10 mins

Function call and execution flow 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 call the function greet.

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

greet[1]
Drag options to blanks, or click blank then click option'
A()
B[]
C{}
D:
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Forgetting the parentheses and just writing the function name.
2fill in blank
medium

Complete the code to return the sum of two numbers from the function.

Python
def add(a, b):
    return a [1] b

result = add(3, 4)
print(result)
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to return the result.
3fill in blank
hard

Fix the error in the function call to print the message.

Python
def say_message(msg):
    print(msg)

say_message[1]
Drag options to blanks, or click blank then click option'
Amsg
Bmsg()
CHello!
D"Hello!"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing a variable name without quotes when a string is needed.
Forgetting the parentheses or quotes.
4fill in blank
hard

Fill both blanks to create a function that returns the square of a number and call it.

Python
def square[1]:
    return x[2]2

result = square(5)
print(result)
Drag options to blanks, or click blank then click option'
A(x)
B**
C*
Dx
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting parentheses around the parameter.
Using multiplication * instead of exponentiation **.
5fill in blank
hard

Fill all three blanks to create a function that filters even numbers from a list and returns a new list.

Python
def filter_even[1]:
    return [num for num in numbers if num [2] 2 == 0]

nums = [1, 2, 3, 4, 5]
even_nums = filter_even[3]
print(even_nums)
Drag options to blanks, or click blank then click option'
A(numbers)
B%
C(nums)
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using equality == instead of modulo % in the condition.
Forgetting to pass the list argument when calling the function.