π§© Functions Quiz for Class 12 β Computational Thinking & Programming-2 (Code 083)
Practice 20 CBSE Class 12 Computer Science (Code 083) MCQs on Python functions β types of functions, creating user-defined functions, arguments & parameters, default and positional parameters, functions returning values, and variable scope (global vs local).
This set includes 6 board-style predict-the-output questions with full working code β the kind that shows up directly in CBSE board papers. Every result below has been verified by actually running the code in Python. Tap any question to reveal the answer with a clear explanation.
π§© Types of Functions
What are the three types of functions in Python?
- Built-in functions, mathematical functions, user-defined functions
- Built-in functions, functions defined in modules, user-defined functions
- User functions, predefined functions, default functions
- Global functions, local functions, system functions
Show Answer & Explanation
β Answer: (b) Built-in functions, functions defined in modules, user-defined functions
Python functions fall into three categories: built-in functions (like print(), always available), functions defined in modules (like math.sqrt(), need an import), and user-defined functions (written by the programmer using def).
π§© Types of Functions
Which of the following is an example of a built-in function?
- my_function()
- print()
- create_function()
- define_function()
Show Answer & Explanation
β Answer: (b) print()
print() is a built-in function β always available without any import or user definition. The other three are just made-up names, not real Python functions.
π§© Types of Functions
How are functions defined in a module accessed in a program?
- By importing the module
- By calling the module
- By including the module in the function definition
- By using a special ‘access’ keyword
Show Answer & Explanation
β Answer: (a) By importing the module
You must first import the module (e.g. import math) before you can use any function defined inside it (e.g. math.sqrt()).
π οΈ User-Defined Functions
What is the main purpose of writing user-defined functions?
- To confuse the program
- To organize code and promote reusability
- To limit the scope of variables
- To slow down program execution
Show Answer & Explanation
β Answer: (b) To organize code and promote reusability
User-defined functions let you break a program into logical, reusable chunks β organizing code and avoiding repetition, since the same function can be called multiple times from different places.
π₯ Arguments and Parameters
What is an argument in the context of functions?
- A variable defined within a function
- A value passed to a function when calling it
- The name of a function
- A module used inside a function
Show Answer & Explanation
β Answer: (b) A value passed to a function when calling it
An argument is the actual value you supply when calling a function β e.g. in greet("Riya"), "Riya" is the argument. (The corresponding name inside the function’s definition, like name, is called a parameter.)
π₯ Arguments and Parameters
What is a default parameter in a function?
- A parameter with a predefined value, used if no value is passed for it
- A parameter that must always be explicitly passed
- A parameter that can only be used in built-in functions
- A parameter that is mandatory in every call
Show Answer & Explanation
β Answer: (a) A parameter with a predefined value, used if no value is passed for it
A default parameter is given a fallback value in the function definition (e.g. def greet(name, msg="Hello"):) β if the caller doesn’t supply a value for it, the default is used instead.
π₯ Arguments and Parameters
Which of the following is a purely positional function call (values matched to parameters by order, not by name)?
- func(parameter=10)
- func(10, parameter=20)
- func(10)
- func(parameter=20, 10)
Show Answer & Explanation
β Answer: (c) func(10)
func(10) passes its value purely by position, matching whichever parameter comes first in the definition. (Option (d), func(parameter=20, 10), isn’t even valid Python β once you use a keyword argument, every argument after it must also be a keyword argument, or you get a SyntaxError.)
β©οΈ Return Values
What is the purpose of a function returning a value?
- To execute the program
- To terminate the program
- To provide a result back to the code that called the function
- To increase the complexity of the code
Show Answer & Explanation
β Answer: (c) To provide a result back to the code that called the function
The return statement sends a result back to the caller, so that value can be stored, printed, or used in further calculations.
β©οΈ Return Values
What is the purpose of the return statement in a function?
- To terminate the entire program
- To skip the next line of code
- To provide a result to the calling code
- To print a message directly to the console
Show Answer & Explanation
β Answer: (c) To provide a result to the calling code
return sends a value back to wherever the function was called from, and immediately ends the function’s execution. It does not print anything by itself, and it only ends the function β not the whole program.
π Scope
What is the scope of a variable defined outside of any function (at the top level of a script)?
- Local scope
- Module scope only, inaccessible elsewhere
- Global scope
- Function scope
Show Answer & Explanation
β Answer: (c) Global scope
A variable defined outside every function has global scope β it can be read (though not directly modified) from anywhere in the program, including inside functions.
π Scope
In Python, what keyword lets you modify a global variable from inside a function?
- var
- global
- declare
- public
Show Answer & Explanation
β Answer: (b) global
The global keyword tells Python that a name inside the function refers to the global variable of that name, not a new local one β allowing the function to actually change its value.
π Scope
Which type of variable is accessible only within the function where it is defined?
- Global variable
- Local variable
- Module variable
- Built-in variable
Show Answer & Explanation
β Answer: (b) Local variable
A local variable is created inside a function and exists only for the duration of that function’s execution β it disappears once the function returns, and can’t be accessed from outside.
π Scope
How can you modify the value of a global variable from within a function?
- It’s simply not possible in Python
- By using a special ‘modify’ keyword
- By redeclaring the variable inside the function using the ‘global’ keyword
- Only by passing it as an argument, never any other way
Show Answer & Explanation
β Answer: (c) By redeclaring the variable inside the function using the ‘global’ keyword
You must explicitly write global variable_name inside the function before changing it. Without that declaration, assigning to the name inside the function just creates a new local variable instead, leaving the global one untouched.
π Scope
In the program below, which variable is local to the function calculate()?
def calculate():
x = 10
return x
y = 20
print(calculate())- x
- y
- Both x and y
- Neither β Python doesn’t have local variables
Show Answer & Explanation
β Answer: (a) x
x is defined inside calculate(), so it’s local to that function and doesn’t exist outside it. y is defined outside any function, making it a global variable. (This question is corrected from the original, which tried to identify a βlocal variableβ purely from its name like localVar β but scope in Python depends entirely on where a variable is defined, never on how it’s named.)
β Board-Style Programs
What does the following program print?
def greet(name, msg="Good morning"):
print(name, msg)
greet("Riya")- Riya
- Good morning
- Riya Good morning
- Error, since msg was not supplied
Show Answer & Explanation
β Answer: (c) Riya Good morning
Since no second argument is given, Python uses the default value for msg: βRiya Good morningβ.
β Board-Style Programs
What does the following program print?
def info(name, age):
print(name, age)
info(age=15, name="Aman")- Aman 15
- 15 Aman
- Error, arguments are in the wrong order
- None None
Show Answer & Explanation
β Answer: (a) Aman 15
With keyword arguments, values are matched by name, not by position β so despite age being written first in the call, Python correctly assigns name="Aman" and age=15: βAman 15β.
β Board-Style Programs
What does the following program print?
def minmax(lst):
return min(lst), max(lst)
a, b = minmax([4, 2, 9, 1])
print(a, b)- 4 1
- 1 9
- 9 1
- Error, a function can only return one value
Show Answer & Explanation
β Answer: (b) 1 9
Python functions can return multiple values by returning a tuple. min([4,2,9,1]) is 1, and max([4,2,9,1]) is 9, so the printed result is β1 9β.
β Board-Style Programs
What does the following program print?
x = 10
def modify():
global x
x = 20
modify()
print(x)- 10
- 20
- Error
- None
Show Answer & Explanation
β Answer: (b) 20
Because of the global x declaration inside modify(), the assignment x = 20 changes the actual global variable β so after calling modify(), x is 20.
β Board-Style Programs
What does the following program print, line by line?
x = 10
def show():
x = 5
print(x)
show()
print(x)- 5, then 10
- 10, then 5
- 5, then 5
- 10, then 10
Show Answer & Explanation
β Answer: (a) 5, then 10
Inside show(), x = 5 creates a brand-new local variable (no global keyword was used), which shadows the outer x only within that function β so it prints 5. The global x outside was never touched, so the final print(x) shows 10.
β Board-Style Programs
What does the following program print?
def greet():
print("Hi")
result = greet()
print(result)- Hi, then Hi
- Hi, then None
- Error, since greet() has no return value
- Hi, then 0
Show Answer & Explanation
β Answer: (b) Hi, then None
greet() prints βHiβ but has no return statement, so it implicitly returns None. First βHiβ is printed inside the function call, then print(result) prints None.
