0% found this document useful (0 votes)
75 views

Functions

This document discusses functions in Python. It contains questions about Python functions including built-in functions, user-defined functions, parameters, arguments, return values, scopes, and more. The questions cover topics like function definitions, passing arguments, recursion, and using functions from modules like random and math.

Uploaded by

Sandeep Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Functions

This document discusses functions in Python. It contains questions about Python functions including built-in functions, user-defined functions, parameters, arguments, return values, scopes, and more. The questions cover topics like function definitions, passing arguments, recursion, and using functions from modules like random and math.

Uploaded by

Sandeep Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Name of the Chapter-FUNCTIONS IN PYTHON

Q QUESTION LEARNING OUTCOME


NO.
1 Function defined in module
Study the following program and select the
possible output :
Import random
X=random.random()
Y=random.randint(0,4)
print(int(x),”:”,y+int(x))
a) -1:0 b)1:6 c)2:4 d)0:3
2 Select output given by the following code Built in function range
a={i:i*I for I in range(6)}
print(a)

a) Dictionary comprehension doesn’t exist


b) {0:0,1:1,2:4,3:9,4:16,5:25,6:36}
c) {0:0,1:1,4:4,9:9,16:16,25:25}
d) {0:0,1:1,2:4,3:9,4:16,5:25}
3 Choose the correct output of the following Python User defined function
code:
def makenew(mystr):
newstr=””
count=0
for x in mystr:
if count%2!=0:
newstr=newstr+str(count)
else:
if x.islower():
newstr=newstr+x.upper()
else:
newstr=newstr+x
count+=1
newstr=newstr+mystr[:1]
print(“The new string is:”,newstr)
makenew(“sTUdeNT”)

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?

1. def printMax(a, b):


2. if a > b:
3. print(a, 'is maximum')
4. elif a == b:
5. print(a, 'is equal to', b)
6. else:
7. print(b, 'is maximum')
8. printMax(3, 4)
a) 3
b) 4
c) 4 is maximum
d) None of the mentioned
8 What will be the output of the following Python Local and global scope of a
code? variable
1. x = 50
2. def func(x):
3. print('x is', x)
4. x=2
5. print('Changed local x to', x)
6. func(x)
7. print('x is now', x)
a)
x is 50
Changed local x to 2
x is now 50
b)
x is 50
Changed local x to 2
x is now 2
c)
x is 50
Changed local x to 2
x is now 100

d) None of the mentioned

9 What will be the output of the following Python Parameter Passing


code?
1. def func(a, b=5, c=10):
2. print('a is', a, 'and b is', b, 'and c is', c)
3.
4. func(3, 7)
5. func(25, c = 24)
6. func(c = 50, a = 100)
a)

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?

def change(one, *two):


print(type(two))
change(1,2,3,4)
a) Integer
b) Tuple
c) Dictionary
d) An exception is thrown
13 If a function doesn’t have a return statement, which Return value of a function
of the following does the function return?
a)int
b) null
c) None
d) An exception is thrown without the return
statement
14 What will be the output of the following Python User defined function
code?

def display(b, n):


while n > 0:
print(b,end="")
n=n-1
display('z',3)
a) zzz
b) zz
c) An exception is executed
d) Infinite loop

15 What will be the output of the following Python Built in function


code?

def find(a, **b):


print(type(b))
find('letters',A='1',B='2')
a) String
b) Tuple
c) Dictionary
d) An exception is thrown
16 Python passes arguments to function by User defined function
1) Reference
2) Value
3) Both
4) None of the above
17 ____________ is a blank space in the beginning of User defined function
a statement within a block.
a. Indention
b. Space
c. Body
d. None of the above

18 These are predefined functions that are always Built in function


available for use. For using them we don’t need to
import any module.
a. Built function
b. Predefined function
c. User defined
d. None of the above
19 A function is said to be___________ if it calls User defined function
itself
a. Built function
b. Pre defined function
c. recursive function
d. None of the above
20 The _________ of a variable is the area of a User defined function
program where it may be referenced
a. External
b. Global
c. Scope
d. Local
21 In which part of memory does the system stores User defined function
the parameter and local variables of function call
a. Heap
b. Stack
c. Both a and b
d. None of the above

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

25 Which of the following is a valid function User defined function


name?
a) start_game()
b) start game()
c) start-game()
d) All 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()

29 Function sqrt() is available under which module of


python?
a. random
b. math
c. statistics
d. None of the above

30 The default value for a parameter is defined in


function .....................?
a. Definition
b. Return statement
c. Header
d. None of the above

31 Function randint() is available under which module


of python?
a. random
b. math
c. statistics
d. None of the above

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

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 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
4 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
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' )

16 Q12. What is the output of the following function call?

a. 8-3
b. Syntax Error
c. -5
d. 5

17 What will be the output of the following code?


def fun(x=10, y=20):
x+=5
y=y-3
return x*y
print(fun(5),fun())

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)

Name of the vetter- INDER PAL SINGH

Name of the KV- KV RBNM SALBONI

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)

Assertion: 50 will be the output of above code.


Reason: Because the x used inside the function study( ) is of local
scope.
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.
6 Read the following statements and then select the answer:
Statement A: Default arguments can be used to add new
parameters to the existing functions
Statement B: Default arguments can be used to combine similar
functions into one
a. Statement A is correct
b. Statement B is correct
c. Both are correct
d. Both are incorrect

7 Assertion (A) : Built in function are predefined in the language


that are used directly
Reason (R) : print() and input() are built in functions
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 the correct explanation
for A.
c. A is true but R is false
d. A is false but R is true

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

Name of the vetter- INDER PAL SINGH

Name of the KV- KV RBNM SALBONI

Region-KOLKATA

Mobile No-8601155337

E-mail ID -inder.harnoorsingh@gmail.com
Name of the Chapter-FUNCTIONS IN PYTHON

TYPE: CASE BASED QUESTION


1.
def myFunction(parameter=”JOHN”):
value = "First"
value = parameter
print (value)

A What will be the output for the User defined


following function call. function
myFunction()
a)First
b)John
c)Error
d)FirstJohn
B What will be the output for the User defined
following function call. function
myFunction(“First”)
a)First
b)John
c)Error
d)FirstJohn
2 Ananya is trying to understand the User defined
features of python functions. She is function
not understanding the feature that
distributes the work in small parts.
Select the appropriate term for her
out of the following:
a) Modularity
b) Reusability
c) Simplicity
d) Abstraction
3 Richa is working with a program User defined
where she gave some values to the function
function. She doesn’t know the term
to relate these values. Help her by
selecting the correct option.
a) function value
b) arguments or parameters
c) return values
d) function call
4 Aman wants to write a function in
python. But he doesn’t know how to
start with it! Select the keyword used
to start a function out of the
following:
a) function
b) start
c) def
d) fun

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.

10 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.
11 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
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)

Assertion: 50 will be the output of above code.


Reason: Beacause the x used insde the function study( ) is of local
scope.
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.
SECTION – C
TRUE-FALSE QUESTIONS
21 In Python function can return only one value. Function return
a. True value.
b. False
22 You can call a function only once after defining it. Calling of
a. True function.
b. False
23 User can change the functionality of a built in functions. Functionality of
a. True a function.
b. False
24 Value returning functions should be generally called from inside of an Function
expression. calling.
a. True
b. False
25 The variable declared outside a function is called a global variable. Local and
a. True Global variable.
b. False
SECTION – D
CASE / SOURCE BASED QUESTIONS
C Consider the code below and answer the questions that follow: Function
B def multiply(number1, number2) : #Line 0 returning
Q answer = number1 * number2 # Line 1 values.
return(answer) #Line 2
1 print(number1, ‘times’, number2, ‘=’ , answer) #Line 3
output = multiply(5, 5) #Line 4
I When the code above is executed, what gets printed?
a) 25
b) 55
c) 5 times 5 = 25
d) Nothing gets printed.
II What will be the value of Variable output equal to after the code is
executed.
a) 25
b) 55
c) 5 times 5 = 25
d) None
III What will be the output of the code if we will place Line3 before Line
2.
a) 25
b) 55
c) 5 times 5 = 25
d) Nothing gets printed.
IV After making the changes according to question (iii) in the code, if we
change the Line 0 as “def multiply(number1, number2 =6):” and Line 4
as “output = multiply(8)” then what will be the output.
a) 25
b) 48
c) 8 times 6 = 48
d) Nothing gets printed.

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.

#Definition of FindPos() function


……… FindPos(AR, ITEM): # Statement-1
size = ………(AR) # Statement-2
if ITEM < AR[0]:
……………….. # Statement-3
else:
pos= -1
for i in range(size-1):
if(AR[i] <= ITEM and ITEM <= AR[i+1]):
pos= i+1
………. # Statement-4
if(pos== -1 and i <= size-1) … # Statement-5
pos= size
return pos
LIST = eval(input("Enter sorted list:"))
ITEM = eval(input("Enter search ITEM:"))
…………….. # Statement-6
print(position)

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

iii. Fill in the blanks in the line marked as Statement-3.


a) return 0
b) Return 0
c) RETURN 0
d) None of the above

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)

Ans. c) position = FindPos(L, ITEM)

2 Tisha is a student of class XII. During examination, she has been


assigned an incomplete python code (shown below). The code
shows the variable scope in a program. Help her in completing the
assigned code.

#Definition of fun() function


…. fun(x, y): # Statement-1
………. a # Statement-2
a = 10
x, y = … # Statement-3
b = 20
b = 30
c = 30
print (a, b, x, y) # Statement-4
a, b, x, y = 1, 2, 3,4
………(50, 100) # Statement-5
fun()
print(a, b, x, y) # Statement-6

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

iv. Mention the output for the line marked as


Statement-4. a) 10 30 100 50
b) 30 10 100 50
c) 100 30 10 50
d) None of the above

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

vi. Mention the output for the line marked as


Statement-4. a) 10 4 3 2
b) 10 3 2 4
c) 10 2 3 4
d) None of the above

Ans. c) 10 2 3 4
Name of the vetter- INDER PAL SINGH

Name of the KV- KV RBNM SALBONI

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

2. A python program execution begins with first statement of


_main_ segment?
a. True
b. False
Ans. True

3. Default parameters can be skipped in function call?


a. True
b. False
Ans. False

4. Variable defined inside functions cannot have global


scope?
a. True
b. False
Ans. False

5. A python function may return multiple values?


c. True
d. False
Ans. True
Name of the vetter- INDER PAL SINGH

Name of the KV- KV RBNM SALBONI

Region-KOLKATA

Mobile No-8601155337

E-mail ID -inder.harnoorsingh@gmail.com

You might also like