Font size
WorksheetsPPL (Quiz 5) Procedures and Functions
Total questions: 25
Worksheet time: 14mins
What is the main difference between a function and a procedure?
Functions return a value, while procedures do not.
Procedures return a value, while functions do not.
Functions are only used in Python, while procedures exist in all languages.
There is no difference between functions and procedures.
In which of the following scenarios is a procedure more appropriate than a function?
Calculating the total price of a shopping cart.
Checking the balance of a bank account.
Transferring money between two accounts.
Converting Celsius to Fahrenheit.
Which of the following is a correct example of a function in Python?
def greet(): print("Hello")
def add(a, b): return a + b
def display(): pass
Both A and B
What is "pass by value" in parameter passing?
The function receives a copy of the variable.
The function modifies the original variable.
The function cannot accept parameters.
The function only works with integers.
What is "pass by reference" in parameter passing?
The function gets a copy of the variable.
The function modifies the original variable.
The function creates a new variable.
The function only accepts strings.
Which type of variable is only accessible inside the function where it is declared?
Global variable
Local variable
Static variable
Reference variable
What will be the output of this code? x = 5 def myFunc(): x = 10 print(x) myFunc() print(x)
10 10
5 5
10 5
Error
What does recursion mean in programming?
A function calling itself
A function calling another function
A function that does not return a value
A function without parameters
Which of the following is a real-world example of recursion?
Printing a receipt
Finding the shortest path in Google Maps
Adding two numbers
Transferring money in a bank
What happens if a recursive function does not have a base case?
It runs forever, causing infinite recursion.
It stops after one call.
It returns an error before execution.
It converts into a loop.
A function can return multiple values.
True
False
The "scope" of a variable determines how long it exists in memory.
True
False
In Python, global variables can be modified inside a function without using global.
True
False
Static variables retain their value between function calls.
True
False
Recursion can always be replaced by loops.
True
False
A programming concept where a function calls itself to solve a smaller instance of a problem.
(Type your answer in ALL SMALL LETTERS)
(a)
The part of a program where a variable is accessible.
(Type your answer in ALL SMALL LETTERS)
(a)
The period during which a variable exists in memory before being destroyed.
(a) of a variable.
(Type your answer in ALL SMALL LETTERS)
The method of passing arguments where the function receives only a copy of the variable.
(Type your answer in ALL SMALL LETTERS)
(a)
The method of passing arguments where the function modifies the original variable.
(Type your answer in ALL SMALL LETTERS)
(a)
A reusable block of code that returns a value after execution.
(Type your answer in ALL SMALL LETTERS)
(a)
A reusable block of code that performs an action but does not return a value.
(Type your answer in ALL SMALL LETTERS)
(a)
The special condition in a recursive function that prevents infinite recursion.
(Type your answer in ALL SMALL LETTERS)
(a)
The keyword in Python used to modify a global variable inside a function.
(Type your answer in ALL SMALL LETTERS)
(a)
A variable that retains its value between function calls in some programming languages.
(Type your answer in ALL SMALL LETTERS)
(a)
