You are on page 1of 5

MCQ BASED ON FUNCTION CHAPTER

1) Which of the following components are part of a function header in Python?


a) Function Name
b) Return Statement
c) Parameter List
d) Both a and c
2) Which of the following function header is correct?
a) def cal_si ( p = 100, r, t = 2 ):
b) def cal_si ( p = 100, r = 8, t ):
c) def cal_si ( p, r = 8, t ):
d) def cal_si ( p, r = 8, t = 2 ):
3) Which of the following is the correct way to call a function my_func?
a) my_func()
b) def my_func()
c) return my_func
d) call my_func()
4) What will be the output of the following python code?
def add (num1, num2):
sum = num1 + num2
s = add(20,30)
print(s)
a) 50
b) 0
c) Null
d) None
5) What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 – 10
return var1+var2
print(my_func(50),my_func())
a. 100 200
b. 150 300
c. 250 75
d. 250 300
6) Best option for the python function is
a) A function is a complete program
b) A function is a block of code identified by its name
c) A function must return a values
d) A function can be called without any call
7) Choose the correct output for the following code
def check(x,y):
if x!=y:
return x+5
else:
return y+10
print(check(10,5))
a) 15
b) 20
c) 5
d) 10
8) def div(lst,n):
for i in range(0,n):
if lst[i] % 5 == 0 :
lst[i]+=5
else :
lst[i]=lst[i]//2
lt=[45,20,23,54,5]
div( lt,len(lt))
for i in lt :
print ( i , end =“#” )
a) 50#25#11.5#27.0#10#
b) 50#25#11#27#10#
c) 50#25#1#0#10#
d) 225#100#1#0#25#
9) Predict the output for the below code snippet :
value = 50
def display(n):
global value
value=25
if n%7==0:
value=value+n
else:
value = value-n
print(value,end=“#”)
display(20)
print(value)
a) 50#50
b) 5#5
c) 50#30
d) 5#50#
10) Choose correct answer
def func1(num):
return num+5
print(fun1(5))
print(num)
a) 10
b) 10 name error
c) Name Error
d) a and c
10) A function may have : -
a) Keyword arguments
b) Default arguments
c) Positional arguments
d) All of the above
11) Identify the correct output :
def func3(a,b,c):
return a+1,b+2,c+3
t=func3(10,20,30)
print(t)
a) 11,22,33
b) 11 22 33
c) (11,22,33)
d) (11 22 33 )
12) Identify correct output for the following code :
def fun(a,b=100):
total=a+b
print(total)
fun(50,20)
a) 100
b) 120
c) 150
d) 70
13) Predict the output for the below code :
a=30
def call(x):
global a
if a%2==0:
x=x+a
else:
x=x-a
return(x)
x=20
print(call(35),end=“#”)
print(call(40),end=“#”)
a) 5#70#
b) 65#70#
c) 60#70
d) Indentation Error
14) Predict the output of the following code :
def fun3(num1,num2):
for x in range(num1,num2):
if x%4==0:
print(x,end=“’)
fun3(10,20)
a) 10 12 16 20
b) 12 16
c) 12 16 20
d) 16
15) Which of the following is not a python function type :
a) Built-in-function
b) user-defined function
c) Module function
d) Absolute function
16) What is the output of the program below?
a=100
def func(a):
a=20
func(a)
print(“a is now”,a)
a) a is now 50
b) a is now 100
c) a is now 20
d) error
17) Write the output for the below code :
z=5
def a_func(x=10,y=20):
z=30
x=x+z
y=y-z
return(x+y)
print(a_func(5), a_func(), z)
a) 20 25 5
b) 25 30 5
c) 10 20 5
d) 25 30 30
18) Predict the output of the following code :
def func1(list1):
for x in list1:
print(x.lower( ), end=“#”)
func1([“New”, “ Delhi”])
a) New,Delhi
b) new#delhi#
c) [new#delhi#]
d) New#Delhi#
19) Choose the correct statement :
a) Default values overrides the values passed by the user
b) Default argument are declared before the positional argument
c) Values passed by user overrides the default values
d) All are correct
20) A variable defined inside function body is known as :
a) global
b) local
c) outer
d) inside
21) What will be the output of the following python code :
def mul(num1,num2):
x=num1*num2
x=mul(20,30)
a) 600
b) None
c) null
d) No output
22) Which of the following function header is correct :
a) def fun( x=1, y )
b) def fun( x=1, y, z=2 )
c) def fun( x=1, y=1, z=2 )
d) def fun( x=1, y=1, z=2, w )
23) What will be the output of the following code :
def div(lst,n):
for i in range(0,n):
if lst[i]>30:
lst[i]=5
else:
lst[i]=lst[i]//2
lt=[45,20,23,54,5]
div(lt,len(lt))
for i in lt :
print(i,end='#')
a) 5#10.0#11.5#5#2.5#
b) 5#10#11#5#2#
c) 5#0#1#5#1#
d) 5#22#25#5#7#
24) Identify the keyword to be used in statement1 so that the identifier value is not local to the function and accessible
through out the program.
a=30
def call(x):
………………….a #Statement1
if a%2==0:
x=x+a
else:
x=x-a
return(x)
x=20
print(call(35),end=’#’)
print(call(40),end=’#’)
a) local
b) global
c) Global
d) constant
25) What is the output of the following code snippet?
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
a) 5#8#15#4#
b) 5#8#5#4#
c) 5#8#15#14#
d) 5#18#15#4#

You might also like