0% found this document useful (0 votes)
71 views7 pages

Python Function MCQ Questions

Uploaded by

deekshitha.c0211
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views7 pages

Python Function MCQ Questions

Uploaded by

deekshitha.c0211
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PRESIDENCY SCHOOL

Bangalore South
MCQ BASED QUESTIONS – WORKING WITH FUNCTION

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. What will be the output of the following code?
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(func1(5))
print(num)

a) 10 b) 10 Name Error c) Name Error d) Both a and c


11. A function may have:
a) Keyword arguments b) Default arguments
c) Positional arguments d) All of the above
12. 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)
13. 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
14. 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

15. 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

16. Which of the following is not a python function type:


a) Built-in-function b) user-defined function
c) Module function d) Absolute function

17. 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

18. 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

19. Predict the output of the following code:


def func1(list1):
for x in list1:
print([Link]( ), end = “#”)
func1([“New”, “Delhi”])

a) New, Delhi b) new#delhi# c) [new#delhi#] d) New#Delhi#

20. Choose the correct statement:


a) Default values overrides the values passed by the user
b) Default arguments are declared before the positional argument
c) Values passed by user overrides the default values
d) All are correct

21. A variable defined inside function body is known as:


a) global b) local c) outer d) inside

22. 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

23. 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 )

24. 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#

25. Identify the keyword to be used in statement1 so that the identifier value is not local
to the function and accessible throughout 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

26. 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#

27. What is the output of the following:


>>> l = (1, 2, 3) + (4, 5) * 3
>>> l

>>> Q = ('a', 'f', 'd', 's') * 2 + (1, 2, 3)


>>> Q

28. What will be the output of the following code:


Local = 100
def Update(Global=0):
global Local
Local += Global
print(Local, "#", Global)

Update(50)
Update()

29. What will be the output of the following code?


g = 20
def add():
global g
g=g+5
print(g,end ='#')
add()
g = 45
print(g,end ='%')

a) 25#45% b) 5#20% c) 25#25% d) 50%20#

30. What will be the output of the following code?


def func(S):
m=''
for i in range(0,len(S)):
if S[i].isalpha( ):
m = m + S[i].upper( )
elif S[i].isdigit( ):
m = m + '0'
else:
m = m + "#"
print(m)
func("Python 3.9")

a) python0#0# b) Python0#0# c) PYTHON#0#0 d) PYTHON0#0#

You might also like