Functions
Functions
a) ST11111s
b) StU1234s
c) sT12345s
d) sT111111
4 Choose the correct output of the following Python User defined function
code:
def ChangeList():
l=[]
l1=[]
l2=[]
for I in range(1,10):
l.append(i)
for i in range(0,1,-2):
l1.append(i)
for i in range (len(l1)):
l2.append(l1[i]+l[i])
l2.append(len(l)-len(l1))
print(l2)
ChangeList()
a)[11,10,9,8,7,4]
b)[11,10,9,8,7,6]
c)[11,10,9,8,7]
d)[10,9,8,7,6,5]
5 Choose the correct output of the following Python User Defined Function and
code: Function defined in module
def Findoutput():
L=”earn”
X=””
L1=[]
Count=1
for I in L:
if i in [‘a’,’e’,’I’,’o’,’u’]:
X=X+i.swapcase()
else:
if(count%2!=0):
X=X+str(len(L[:count]))
else:
X=X+i
Count=count+1
Print(X)
Findoutput()
a)EArn
b)EA3n
c)EA34
5)EARN
6 Which output is not expected from the following Function defined in module
program:
import random
X=3
N=random.randint(1,x)
for i in range(N):
print (I,”#”,i+1)
a)0#1
b) 1#2
c)2#3
d)3#4
7 What will be the output of the following Python User Defined Function
code?
a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
b)
a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
a is 50 and b is 100 and c is 5
c)
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
d) None of the mentioned
10 What will be the output of the following Python User defined function
code?
1. def maximum(x, y):
2. if x > y:
3. return x
4. elif x == y:
5. return 'The numbers are equal'
6. else:
7. return y
8.
9. print(maximum(2, 3))
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned
11 What will be the output of the following Python User defined function
code?
def change(i = 1, j = 2):
i=i+j
j=j+1
print(i, j)
change(j = 1, i = 2)
a) An exception is thrown because of conflicting
values
b) 1 2
c) 3 3
d) 3 2
12 What will be the output of the following Python Built in function
code?
22 When you use multiple type argument in function User defined function
then default argument take place
1) At beginning
2) At end
3) Anywhere
4) None of the above
23 A Function that does not have any return value is User defined function
known as……………….
1) Library function
2) Void function
3) Fruitful function
4) None of the above
24 when large programs are broken down into smaller User defined function
units known as………………
a. sub program
b. functions
c. class
d. None of the above
26 Which of the following is not a part of the python User defined function
function?
a) function header
b) return statement
c) parameter list
d) function keyword
27 If the return statement is not used in the function User defined function
then which type of value will be returned by the
function?
a) int
b) str
c) float
d) None
28 Divya wants to print the identity of the object used in-built functions
in the function. Which of the following functions is
used to print the same?
a) identity()
b) ide()
c) id()
d) idy()
32
ANSWERS
Question No Answer
1 d
2 d
3 a
4 a
5 b
6 d
7 c
8 a
9 c
10 b
11 d
12 b
13 c
14 a
15 c
16 b.)python passes arguments to function by value
17 a)Indentation is the blank space in the beginning of a statement
within a block
18 a)Built in functions are predefined functions that are always
available for use.For using them we do not need to import any
module. For example:len(),type(),int(),input().
19 c) recursive function is a function which calls itself
20 c) scope of a variable is the area of the program where it may be
referenced
21 b) Stack
22 2) at end
23 2) void function
24 b)functions
25 a)
26 d)
27 d)
28 c)
29 b)
30 (c)
31 (a)
32
MCQ BASED QUESTIONS
a. 100
b. 50
c. Error
d. None of the above
5 Which of the following functions header is correct? How to give
a. def study(a=2, b=5, c) : default value to
b. def study(a=2, b, c=5) : a function.
c. def study(a, b=2, c=5):
d. none of the above
6 A variable created or defined within a function body is Local and
a. local global variable
b. global in a function.
c. built in
d. instance
7 In _______________ arguments we can skip the default argument, but Arguments of a
all the arguments should match the parameters in the function function.
definitions.
a. keyword
b. required
c. default
d. none of the above.
8 By default if you return multiple value separated by comma, then it is Function
returned as returning values
a. List
b. Tuples
c. String
d. None of the above.
9 Find the output of following code : Local and
x=100 global variables.
def study(x):
global x
x=50
print(“Value of x is :”, x)
a. 100
b. 50
c. Error
d. None of the above
10 The values being passed through function-call statement are called Function
________________. passing values.
a. arguments
b. parameter
c. values
d. none
11 The values received in function definition/header statement are called Function
______________ . passing values.
a. arguments
b. parameter
c. values
d. none
12 What will be the output of the following code: How to return a
def calculate(a, b): value by a
return a+b, a-b
function.
res = calculate(7, 7)
print(res)
a. (14,0)
b. [14, 0]
c. 14
d. 0
13 Which of the following function header is correct :
a. def discount(rate=7,qty,dis=5)
b. def discount(rate=7,qty,dis)
c. def discount(rate,qty,dis=5)
d. def discount(qty,rate=7,dis)
14 Select which of the following is NOT TRUE for Python function:
a. A function only executes when it is called and we can
reuse it in a program
b. In a python function a keyword argument can not be
followed by a positional argument
c. A Python function can return multiple values
d. Python function doesn’t return anything unless and until
you add a return statement
15 Select the correct function call for the following given function
fun1():
a. fun1(name='Emma', age=23,'Female')
b. fun1(age='23', name='Emma', gender='female')
c. fun1('Emma', age=23, Gender='Female')
d. func1('Emma', 23, 'Female' )
a. 8-3
b. Syntax Error
c. -5
d. 5
a. 20, 200
b. 170, 255
c. 85, 200
d. 300, 500
18 What will be the output of the following code?
v = 80
def display(n):
global v
v = 15
if n%4==0:
v += n
else:
v -= n
print(v, end="#")
display(20)
print(v)
a. 80#80
b. 80#100
c. 80#35
d. d 80#20
ANSWERS
1 (a) Function
2 (a) Indention
3 (d) functions defined in module
4 (a) 100
5 (c) def study(a, b=2, c=5)
6 (a) local
7 (a) Keyword
8 (b) tuples
9 (b) 50
10 (a) arguments
11 (b) parameter
12 (a) (14, 0)
13 (c)
14 (d)
15 (b)
16 (d)
17 (b)
18 (c)
Region-KOLKATA
Mobile No-8601155337
E-mail ID -inder.harnoorsingh@gmail.com
Name of the Chapter-FUNCTIONS IN PYTHON
1 Assertion: The function header ‘def read (a=2, b=5, c):’ is not Defining a
correct. default
Reason: Non default arguments can’t follow default arguments. argument.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is the
correct explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is flase, reason is true.
2 A function code is given as follows: Calling a
def study (num = 5): function having
print(num + 5) default
Assertion: We can call the above function either by statement argument.
‘study(7)’ or ‘study( )’.
Reason: As the function contains default arguments, it depends on the
caller that the above function can be called with or without the value.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is the
correct explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
3 Assertion: len( ), type( ), int( ), input( ) are the functions that are Built in
always available for use. functions.
Reason: Built in functions are predefined functions that are always
available for use. For using them we don’t need to import any module.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is the
correct explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
4 Assertion: Every function returns a value if the function does not Function
explicitly return a value, then it will return ‘Zero’. returning a
Reason: Zero is equivalent to None. value.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is the
correct explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
5 Consider the following code: Local and
x = 100 Global scope of
def study( ):
a function.
global x
x = 50
print(x)
ANSWERS
1 (a)
2 (a)
3 (a)
4 (c)
5 (c)
6 (c)
7 (b)
TYPE ARQ(5)
DIRECTIONS: In the following questions, A statement of Assertion (A) is followed by a
statement of Reason (R). Mark the correct choice as:
(A) Both A and R are true and R is the correct explanation for A
(B) Both A and R are true and R is not correct explanation for A
(C) A is true but R is false
(D) A is false but R is true
QNO ASSERTION - REASONING LEARNING ANSWER
OUTCOME
1. Assertion(A): Built in function are predefined in Built in B
the language that are used directly function
Reason(R): print() and input() are built in functions
2. Assertion(A):Keyword arguments are related to the Argument A
function calls passing
Reason(R): When you use keyword arguments in a
function call, the caller identifies the arguments by
the parameter name
3. Assertion(A): A function is a block of organized User A
and reusable code that is used to perform a single, defined
related action function
Reason(R): Function provides better modularity by
your application and a high degree of code
reusability.
4 Assertion(A): It is not possible to delete/remove the Built in D
elements from a list function
Reason(R): The pop(), remove(), del() functions are
used to remove/delete the elements from the list.
5 Assertion(A): There are various built in Built in C
functions/methods to manipulate the dictionaries function
Reason(R): Built in functions does not work on
dictionaries
Region-KOLKATA
Mobile No-8601155337
E-mail ID -inder.harnoorsingh@gmail.com
Name of the Chapter-FUNCTIONS IN PYTHON
ANSWER
CBQ NO Answer
1 A) b
1 B) a
2 a
3 b
4 c
SECTION - A
MCQ (Multiple Choice Questions)
Sl. Question Learning
No objectionv
1 A ______________ is a block of code that will execute only when it is Define a
called. function.
a. Function
b. Sub Program
c. Block
d. All of the above
2 ________________ is the blank space in the beginning of a statement How to write
within a block. function.
a. Indention
b. Space
c. Body
d. None of the above
3 Every function return a value if function don’t explicitly return a value, How function
then it will return __________ . return values.
a. return
b. None
c. Value
d. All
4 There are predefined functions that are available in module. For using Built in
them we need to import module functions.
a. built-in functions
b. predefined functions
c. user defined functions
d. function defined in module
5 The ______________ of a variable is the area of the program where it Local and
may be referred. Global Scope of
a. external a variable.
b. global
c. scope
d. local
6 Find the output of following code : Local and
x=100 Global Variable
def study(x):
x=50
print(“Value of x is :”, x)
a. 100
b. 50
c. Error
d. None of the above
7 Which of the following functions header is correct? How to give
a. def study(a=2, b=5, c) : default value to
b. def study(a=2, b, c=5) : a function.
c. def study(a, b=2, c=5):
d. none of the above
8 A variable created or defined within a function body is Local and
a. local global variables
b. global in a function.
c. built in
d. instance
9 In _______________ arguments we can skip the default argument, but Arguments of a
all the keyword arguments should match the parameters in the function function.
definitions.
a. keyword
b. required
c. default
d. none of the above.
a. 100
b. 50
c. Error
d. None of the above
12 The values being passed through function-call statements are called Function
________________. passing values.
a. arguments
b. parameter
c. values
d. none
13 The values received in the function definition/header statement are Function
called ______________ . passing values.
a. arguments
b. parameter
c. values
d. none
14 In which part of memory does the system stores the parameter and Function
local variables of function call. calling.
a. Heap
b. Stack
c. Both a and b
d. None of the above
15 What will be the output of the following code: How to return a
def calculate(a, b): values by a
return a+b, a-b function.
res = calculate(7, 7)
print(res)
a. (14,0)
b. [14, 0]
c. 14
d. 0
SECTION - B
ARQ (Assertion Reason Questions)
16 Assertion: The function header ‘def read (a=2, b=5, c):’ is not Defining a
correct. default
Reason: Non default arguments can’t follow default arguments. argument.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is correct
explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is flase, reason is true.
17 A function code is given as follows: Calling a
def study (num = 5): function having
print(num + 5) default
Assertion: We can call the above function either by statement argument.
‘study(7)’ or ‘study( )’.
Reason: As the function contains default arguments, it depends on the
caller that the above function can be called with or without the value.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is correct
explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
18 Assertion: len( ), type( ), int( ), input( ) are the functions that are Built in
always available for use. functions.
Reason: Built in functions are predefined functions that are always
available for use. For using them we don’t need to import any module.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is correct
explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
19 Assertion: Every function return a value if the function does not Function
explicitly return a value, then it will return ‘Zero’. returning a
Reason: Zero is equivalent to None. value.
Please choose the correct choice out of the four options given
below:
a. Both Assertion and reason are true and reason is correct
explanation of assertion.
b. Assertion and reason both are true but reason is not the
correct explanation of assertion.
c. Assertion is true, reason is false.
d. Assertion is false, reason is true.
20 Consider the following code: Local and
x = 100 Global scope of
def study( ): a function.
global x
x = 50
print(x)
C Consider the code below and answer the questions that follow:
B pos = 200
Q level = 1
def play( ):
2 max_level = level + 10
return max_level
res = play( )
print(res)
I Which of the following is the local variable?
a. res
b. pos
c. level
d. max_level
II Which of the following is a global variable?
a. res
b. pos
c. Both a and b
d. None of the above.
III What will be the output of above code?
e. 1
f. 11
g. 10
h. All of the above
IV Which of the following is not a local variable?
a. pos
b. level
c. res
d. All of the above.
C Function Arguments:
B These are the values provided in the function call
Q /invoke statement. Required arguments are the arguments
passed to a function in correct positional order. Keyword
3
arguments are related to the function calls. When you use
keyword arguments to a function call, the caller identifies the
arguments by the parameter name. A default argument is the
argument that assumes a default value, if a value is not provided
in the function call for that argument
I How many types of arguments are there in functions?
a. 2
b. 3
c. 4
d. 5
II Which argument is an argument that assumes a default value?
a. Default argument
b. Positional argument
c. Keyword argument
d. None of these
III Which arguments are also known as positional arguments?
a. Keyword argument
b. Default argument
c. Required argument
d. Variable length argument
IV Which of these is/are formal argument(s)?
a. Required argument
b. Keyword argument
c. Default argument
d. All of these
V ________are the values provided in the function call/invoke
statement.
a. Functions
b. Arguments
c. Preprocessor
d. Models
ANSWERS
Q. (d)
1(I)
(II) (a)
(III) (a)
(IV) (c)
Q2 (d)
(I)
(II) (c)
(III) (b)
(IV) (d)
Q3 (c)
(I)
(II) (a)
(III) (c)
(IV) (d)
(V) (b)
Q. Question
No.
1 Alfred is a student of class XII. During examination, he has been
assigned an incomplete python code (shown below) to find position
of an ITEM in a sorted list (ascending order) AR.
Help him in completing the assigned code to search an item.
i. Identify the suitable keyword for blank space in the line marked
as Statement-1.
a) define
b) def
c) DEF
d) Def
Ans. b) def
ii. Identify the suitable function name to calculate the length of AR
for blank space in the line marked as Statement-2.
a) SIZE
b) LENGTH
c) length
d) len
Ans. d) len
Ans. a) return 0
iv. Identify the suitable jump statement for the blank space in the
line marked as Statement-4.
a) pass
b) break
c) continue
d) None of the above
Ans. b) break
v. Identify the suitable special symbol for the blank space in the
line marked as Statement-5.
a) ;
b) ,
c) :
d) ”
Ans. c) :
vi. Write down a suitable function call statement for the blank space
in the line marked as Statement-6.
a) FindPos(AR, ITEM)
b) FindPos(L, ITEM)
c) position = FindPos(L, ITEM)
d) position = findpos(L, ITEM)
i. Identify the suitable keyword for blank space in the line marked
as Statement-1.
a) define
b) def
c) DEF
d) Def
Ans. b) def
ii. Identify the suitable keyword to access variable a globally for
blank space in the line marked as Statement-2.
a) local
b) global
c) static
d) None of the above
Ans. b) global
iii. Write down the python to swap the values of x and y for the
blank space in the line marked as Statement-3.
a) y,x
b) Y, X
c) swap(x,y)
d) None of the above
Ans. a) y,x
Ans. a) 10 30 100 50
v. Identify the missing code for the blank space in the line marked
as Statement-5.
a) fun
b) FUN
c) Fun
d) None of the above
Ans. a) fun
Ans. c) 10 2 3 4
Name of the vetter- INDER PAL SINGH
Region-KOLKATA
Mobile No-8601155337
E-mail ID -inder.harnoorsingh@gmail.com
Name of the Chapter- FUNCTIONS IN PYTHON
TYPE: TRUE/FALSE(5)
Q QUESTION LEARNING
NO OUTCOME
1 In python functions can return only one value. RETURN
2 Actual parameters are the parameters specified within a pair of PARAMETER
parentheses in the function definition PASSING
3 Python passes parameters by value PARAMETER
PASSING
4 Value returning functions should be generally called from inside FUNCTION
an expression CALLING
5 Function header and function definition is same thing USER DEFINED
FUNCTION
6 You can call a function only once after defining it. Calling of
a. True function.
b. False
7 User can change the functionality of a built in functions. Functionality of
a. True a function.
b. False
8 The variable declared outside a function is called a global variable. Local and
a. True Global variable.
b. False
9 The default valued parameter specified in the function header
becomes optional in the function calling statement.
a. True
b. No
ANSWER
Question No Answer
1 FALSE
2 FALSE
3 TRUE
4 TRUE
5 FALSE
6 FALSE
7 FALSE
8 TRUE
9 TRUE
Q. No. Question
1. Function makes a program more readable and reduces
the program size?
a. True
b. False
Ans. True
Region-KOLKATA
Mobile No-8601155337
E-mail ID -inder.harnoorsingh@gmail.com