Important QnA Working with functions Class 12

In this article, you will get important QnA Working with functions Class 12. So let us start this article with theory questions for working with functions in class 12 computer science.
In the first section of Working with functions Class, 12 theory-based questions will be discussed. Let’s start the article Working with functions Class 12 Questions and Answers. 

Theory-based questions for Working with functions Class 12

1. What is a function?
  • A function is a set of instructions or subprograms that are used to fulfil the user’s need. 
  • In other words, a function is a bunch of code which performs a specific task. 
  • A function is used to do a specific task and divide the large program into smaller blocks. 
  • A function is a small unit of a program that processes the data and often returns a value.
2. Why do programmers need functions in python programming?
  • To make the program easy
  • Divide the large program into a small block of codes
  • Reduce the lines of code
  • Easy to update
3. How to create a function in python? Explain in detail.
Ans.: To create a function in python follow the given steps:
  • Start the code with def followed by function name and supply input through the parameters. 
  • Write the set of statements to be executed in the program.
  • Call the function to invoke or execute the statements. 
Parts of functions - Working with functions Class 12
4. What are the parts of functions? Explain with a suitable example.
Ans.: The arts of functions are as follows:
  1. Function header: It starts with def followed by the function name and required parameters. Parameters are the input variables written into brackets. These parameters are supplied in the function calling statement. 
  2. Function Body: This is the main part of a program. It contains the main block of the program. The set of instructions such as calculations, logical comparisons etc is written here in this part. It ends with a return statement. Indentation is very important for the function body. 
  3. Function calling statement: This is the final part of a function. It invokes the function and returns the output as instructed into the function body. 
Part Description
Function Header Always starts with the “def” keyword followed by the function name and its parameters, and ends with a colon (:)
Parameters Variablessupplied in brackets of the function header
Function Body Block of statements/instructions that define the action performed by the function, indentation must be followed
Indentation White space at the beginning of every statement with the same block
Function Calling writing function name including parameter values
5. How to call a function? Write steps.
Ans: Calling a function is an easy task. Here are the steps:
  • Write the function name.
  • Supply the values of the parameters, if any. 
6. What are the comments? What are the role comments in the program? How to write single-line comments and multi-line comments?
Ans.: Comments are the additional explanatory text written in the function to provide some description or explanation about the statement or block of code. 
Comments play an important role in understanding a program. It provides a descriptive explanation of the written statements. It makes the intention very clear for what the statement is used or what process is going to be done.
The single-line comment is written by # followed by the text. The multiline comments start with ”’ and are followed by the text then ends with ”’. 
7. Explain the physical line structure of a program. Illustrate with an example.
Ans.: The physical line structure of a program contains the lines of codes. Physical lines are the lines which you can see on the screen in a python program. 
In other words, a physical line contains a set of characters that ends with an EOL character. The EOL character is newline generally ‘\n’ in python. 
>>> name=’Chapter 3 Working with functions’
>>> print(name) 
Chapter 3 Working with functions
The above statement is same as:
>>> name=’Chapter 3 Working with functions’; print(name)
8. Illustrate the flow of execution in the function call statement.
  • A function in the python program is called by a function call statement
  • To call a function, write the function name followed by parameter values in brackets
  • A block of statements executed in the execution frame
  • When a function is called, an execution frame is created and controls the transfer
  • Within the execution frame, the statements written in the function body are executed and return a value or execute the last statement
  • Python follows top to bottom approach for executing program
  • Comments are ignored in execution
  • If python notices function definition with a def statement it just executes the function header line and skips all statements in the function body these statements execute when a function will be called
9. Write and explain the types of functions supported by python.
  • Built-in Functions: Pre-defined functions of python such as len(), type(), input() etc.
  • Functions defined in modules: Functions defined in particular modules, can be used when the module is imported. A module is a container of functions, variables, constants, and classes in a separate file which can be reused.
  • User-Defined Functions: Function created by the programmer
In the next section of Working with Functions Class 12 questions and answers, we are going to discuss some questions based on topics arguments, and parameters for Working with Functions Class 12. 
10. Write the ways of import module in the python program.
  • The module can be imported in two ways
    • import statement: Used to import the entire module. EX. import math
    • from statement : import all functions or the selected one. EX. from random import randint
11. Differentiate between parameters and arguments.
Parameters Arguments
These are specified during the function definition. Values passed during the function call.
 They are also known as formal parameters. They are also known as actual parameters.
The values passed as parameters are local variables and are assigned values of the arguments during the function call. Every argument is assigned to a parameter when the function is defined.
These variables help in the complete execution of the function. These variables are passed to the function for execution.
The values contained by these parameters can only be accessed from function return statements or if the scope of these parameters is made global.  The arguments are accessible throughout the program depending upon the scope of the variable assigned. 
12. What are the arguments supported by python? Explain each of them with a suitable example.
Ans.:Python supports four argument types:


  1. Positional Arguments: Arguments passed to a function in correct positional order, no. of arguments must match with no. of parameters required.
  2. Default Arguments: Assign a default value to a certain parameter, it is used when the user knows the value of the parameter, default values are specified in the function header. It is optional in the function call statement. If not provided in the function call statement then the default value is considered. Default arguments must be provided from right to left.
  3. Key Word Arguments: Keyword arguments are the named arguments with assigned values being passed in the function call statement, the user can combine any type of argument.
  4. Variable Length Arguments: It allows the user to pass as many arguments as required in the program. Variable-length arguments are defined with the * symbol.

13. What is the local variable and global variable? Explain with an example.


Global Variable: A variable that is declared in top-level statements is called a global variable. To access the value of a global variable user need to write a global keyword in front of the variable in a function. 

Local Variable: A name declared in a specific function body is called a local variable. 

In the next section of Working with functions Class 12 questions, I will cover some output and error-based questions. Here we go!
14. What are the rules for combining three types of arguments in a Python function?
Ans.: The following rules need to be followed for combining three types of arguments in a python function. 

1. An argument list must contain positional arguments followed by any keyword argument.

2. Keyword arguments should be taken from the required arguments preferably.

3. Value of the argument can’t be specified more than once.


cal_discount(amt=500,rate=10) or cal_discount(rate=10,amt=500)

In the next section of Working with Functions Class 12 we are going through the output questions. 

Output Questions Working with functions Class 12

1. def Fun1():
          print(‘Python, let\’s fun with functions’)
Python, let’s fun with functions
Explanation: Fun1 is a user-defined function having 1 statement with \ to print ‘ in output. 
2.def add(i):
        return i
Explanation: In the first function call statement 10 is passed as a value, so i*3%2=10*3%2=30%2=0, hence prints square of 10 i.e. 100. In the second function call statement 5 is passed as a value, so i*3%2=5*3%2=15%2=1, hence else block will be executed, and its i=i*4 t*4=20. 
3. import math
    def area(r):
        return math.pi*r*r
Explanation: In function, call value is passed 10. Hence the calculation will be 3.14*100=314.
4.def fun1(x, y):
        x = x + y
        y = x – y
        x = x – y
        print(‘a =’,x)
        print(‘b =’,y)
    a = 5
    b = 3
a = 3
b = 5
4. def div5(n):
        if n%5==0:
            return n*5
            return n+5
   def output(m=5):
        for i in range(0,m):
            print(div5(i),’@’,end=” “)
0 @ 6 @ 7 @ 8 @ 9 @ 25 @ 11 @
0 @ 6 @ 7 @ 8 @ 9 @
0 @ 6 @ 7 @
Explanation: In first calling for output(7) loop executes 7 times. and returns 5 as 25 and the rest will be incremented by 5 hence the first line is generated. 
In the second calling function no value is passed so it takes the default argument and the loop terminates when the of i is 5. 
In the third calling, the function value is passed as 3 so there is no value which a multiple of 5. 
5.def sum(*n):
        for i in n:
            print(‘Sum=’, total)
6.def func(b):
        global x
        print(‘Global x=’, x)
        y = x + b
        x = 7
        z = x – b
        print(‘Local x = ‘,x)
        print(‘y = ‘,y)
        print(‘z = ‘,z)
7. def func(x,y=100):
        temp = x + y
        x += temp
8. def get(x,y,z):
    def put(z,y,x):

In the next section Working with functions Class 12 questions and answers, we are going through error-based questions.

Error-based questions working with functions class 12 computer science

1. def in(a,b)
        a=a + b
2. void get(x=10,y):
    x = x + y
3. // Program to compute the result
    def res():
        eng = 56
        math = 40
        sci = 60
        if eng<=35 || math<=35 ||
            print(‘Not Qualified’)
4. a=5, b=10
    def swap(x,y):
        x = a + b
        y = x – y
        x = x – y
5. def cal_dis(qty,rate=50,dis_rate): #discount rate = 5%
        bil_amt = (qty*rate)*dis_rate
6. def Sum(C) #Method to find sum
         for I in range(1,C+1):
         RETURN S
   print (Sum[2]) #Function Call

Follow this link to read notes:

In the next section of Working with functions Class 12 questions and answers you will get the programs based Working with functions topic.

Python Practical programs with solutions Working with functions Class 12

In the below link you will get some solved programs on Working with functions Class 12. This will help you prepare your practical file. This link also contains Type C Practical questions from Sumita Arora Text Book exercise or Sumita Arora Book Questions with solutions for the chapter Working with functions Class 12.

CS Class 12 Practical Programs Working with functions

Watch this video for solutions to Output and error questions of the chapter Working with Functions Class 12:That’s all from the chapter Working with Functions Class 12 questions and answers. If you have any doubts or queries feel free to ask in the comment section.

Thank you for reading the Working with Functions Class 12 questions and answers. Visit my blog website for more articles like Working with functions Class 12 questions answers.

Give your valuable suggestions in the comment section for Working with Functions Class 12 questions and answers.

8 thoughts on “Important QnA Working with functions Class 12”

Leave a Reply