Functions Quiz for Class 12

🧩 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πŸ› οΈ User-Defined FunctionsπŸ“₯ Arguments & Parameters↩️ Return Values🌐 Scope⭐ Board-Style Programs
Q1
🧩 Types of Functions

What are the three types of functions in Python?

  1. Built-in functions, mathematical functions, user-defined functions
  2. Built-in functions, functions defined in modules, user-defined functions
  3. User functions, predefined functions, default functions
  4. 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).

Q2
🧩 Types of Functions

Which of the following is an example of a built-in function?

  1. my_function()
  2. print()
  3. create_function()
  4. 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.

Q3
🧩 Types of Functions

How are functions defined in a module accessed in a program?

  1. By importing the module
  2. By calling the module
  3. By including the module in the function definition
  4. 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()).

Q4
πŸ› οΈ User-Defined Functions

What is the main purpose of writing user-defined functions?

  1. To confuse the program
  2. To organize code and promote reusability
  3. To limit the scope of variables
  4. 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.

Q5
πŸ“₯ Arguments and Parameters

What is an argument in the context of functions?

  1. A variable defined within a function
  2. A value passed to a function when calling it
  3. The name of a function
  4. 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.)

Q6
πŸ“₯ Arguments and Parameters

What is a default parameter in a function?

  1. A parameter with a predefined value, used if no value is passed for it
  2. A parameter that must always be explicitly passed
  3. A parameter that can only be used in built-in functions
  4. 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.

Q7
πŸ“₯ Arguments and Parameters

Which of the following is a purely positional function call (values matched to parameters by order, not by name)?

  1. func(parameter=10)
  2. func(10, parameter=20)
  3. func(10)
  4. 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.)

Q8
↩️ Return Values

What is the purpose of a function returning a value?

  1. To execute the program
  2. To terminate the program
  3. To provide a result back to the code that called the function
  4. 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.

Q9
↩️ Return Values

What is the purpose of the return statement in a function?

  1. To terminate the entire program
  2. To skip the next line of code
  3. To provide a result to the calling code
  4. 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.

Q10
🌐 Scope

What is the scope of a variable defined outside of any function (at the top level of a script)?

  1. Local scope
  2. Module scope only, inaccessible elsewhere
  3. Global scope
  4. 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.

Q11
🌐 Scope

In Python, what keyword lets you modify a global variable from inside a function?

  1. var
  2. global
  3. declare
  4. 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.

Q12
🌐 Scope

Which type of variable is accessible only within the function where it is defined?

  1. Global variable
  2. Local variable
  3. Module variable
  4. 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.

Q13
🌐 Scope

How can you modify the value of a global variable from within a function?

  1. It’s simply not possible in Python
  2. By using a special ‘modify’ keyword
  3. By redeclaring the variable inside the function using the ‘global’ keyword
  4. 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.

Q14
🌐 Scope

In the program below, which variable is local to the function calculate()?

def calculate():
    x = 10
    return x

y = 20
print(calculate())
  1. x
  2. y
  3. Both x and y
  4. 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.)

Q15
⭐ Board-Style Programs

What does the following program print?

def greet(name, msg="Good morning"):
    print(name, msg)

greet("Riya")
  1. Riya
  2. Good morning
  3. Riya Good morning
  4. 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”.

Q16
⭐ Board-Style Programs

What does the following program print?

def info(name, age):
    print(name, age)

info(age=15, name="Aman")
  1. Aman 15
  2. 15 Aman
  3. Error, arguments are in the wrong order
  4. 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”.

Q17
⭐ 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)
  1. 4 1
  2. 1 9
  3. 9 1
  4. 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”.

Q18
⭐ Board-Style Programs

What does the following program print?

x = 10
def modify():
    global x
    x = 20

modify()
print(x)
  1. 10
  2. 20
  3. Error
  4. 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.

Q19
⭐ Board-Style Programs

What does the following program print, line by line?

x = 10
def show():
    x = 5
    print(x)

show()
print(x)
  1. 5, then 10
  2. 10, then 5
  3. 5, then 5
  4. 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.

Q20
⭐ Board-Style Programs

What does the following program print?

def greet():
    print("Hi")

result = greet()
print(result)
  1. Hi, then Hi
  2. Hi, then None
  3. Error, since greet() has no return value
  4. 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.

Jitendra Singh
βœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me β†’