R4RIN
MCQS
Python MCQ Quiz Hub
Python Functions MCQS Set 1
Choose a topic to test your knowledge and improve your Python skills
1. The process of dividing a computer program into separate independent blocks of code with specific functionalities is known as _________.
Programming
Modular Programming
Modular Programming
Step Programming
2. _____________ can be defined as a named group of instructions that accomplish a specific task when it is invoked/called.
Function
Datatype
Token
Operator
3. In a program, a function can be called ____________ times.
2
3
5
Multiple times
4. Which keyword is used to begin the definition of a function?
Define
DEF
def
Def
5. Which of the following statement is a function call?
call sum( )
def sum( )
sum( )
function sum( )
6. Which of the following are advantages of using function in program?
It increases readability of program.
It increases reusability.
It makes debugging easier.
All the above
7. Function defined to achieve some task as per the programmer’s requirement is called a __
user defined function
library function
built in functions
All the above
8. Functions which are already defined in python is called a ________
user defined function
library functions
built in functions
Both b and c
9. Which of the following statement is not true regarding functions?
A function definition begins with “define”
A function may or may not have parameters.
A function may or may not return value.
Function header always ends with a colon (:).
10. Which of the following statement is outside the function “sum”? def sum(): a = int(input(“Enter number”))#Statement 1 b = int(input(“Enter number”)) #Statement 2 s = a + b #Statement 3 print(s) #Statement 4
Statement 1
Statement 2
Statement 3
Both Statement 3 and Statement 4
11. The function can be called in the program by writing function name followed by ___
[ ]
{ }
( )
None of the above
12. def cal(n1) : What is n1?
Parameter
Argument
Keyword
None of the above
13. Write the output of the following: def s(n1): print(n1) n2=4 s(n2)
2
3
4
Error
14. Which of the following statement will execute in last? def s(n1): #Statement 1 print(n1) #Statement 2 n2=4 #Statement 3 s(n2) #Statement 4
Statement 1
Statement 2
Statement 3
Statement 4
15. Choose the correct answer: def s(n1): print(n1) n2=4 s(n2) Statement A : n1 and n2 have same memory Address Statement B : both n1 and n2 are referring to the same value, so they have same identity
Statement A is True and Statement B is False
Statement A is False and Statement B is True
Both the statements are True
Both the statements are False
16. Consider the following code and choose the incorrect statement.: def s(n1): print(id(n1)) n2=4 s(n2) print(id(n2))
Function name is ‘s’
Function ‘s’ is taking one parameter.
Both print statement will print the same value.
Both print statement will print different value.
17. Write the output of the following: def cal(m,n): if m==n: return m*3 else: return m*2 s = cal(9, 8) print(s)
16
18
27
24
18. Write the output of the following: def cal(m,n): if m==n: return m*3 else: return n*2 s = cal("Amit", "Anuj") print(s)
AmitAmitAmit
AmitAmit
AnujAnujAnuj
AnujAnuj
19. Write the output of the following: def fn(n1, n2=7): n1=n1+n2 print(n1) fn(3, 9)
3
9
12
10
20. Write the output of the following: def fn(n1, n2=7): n1=n1%n2 print(n1) fn(3%2, 9%2)
1
0
2
3
21. Which of the following function definition header is wrong?
def sum(n1, n2, n = 3):
def scan(p1, p2 = 4, p3 = 5):
def div(p1=4, p2, p3):
def mul(p1, n1, m1):
22. Functions which do not return any value is called ___
default function
zero function
void function
null function
23. The ____________ statement returns the values from the function to the calling function.
send
give
return
take
24. The return statement in function is used to _____
return value
returns the control to the calling function
Both of the above
None of the above
25. Choose the correct statement
We can create function with no argument and no return value.
We can create function with no argument and with return value(s)
We can create function with argument(s) and no return value.
All of the above
26. Write the output of the following: sound() def sound(): print("sound" * 2)
sound
soundsound
NameError : name ‘sound’ is not defined
SyntaxError: invalid syntax
27. A function may return multiple values using _
List
Tuple
String
Dictionary
28. The part of the program where a variable is accessible is known as the __________ of that variable
scope
module
part
None of the above
29. Which of the following is not the scope of variable?
Local
Global
Outside
None of the above
30. A variable that is defined inside any function or a block is known as a ___
Global variable
Local variable
Function Variable
inside variable
31. Fill in the blank so that the output is 9: a = 9 def sound(): ________ a print(a) sound()
local
global
outer
var
32. Write the output of the following: a = 9 def sound(): b = 7 print(a) sound() print(b)
7 7
9 9
7 9
Error
33. How many built-in functions are used in the following code: a = int(input("Enter a number: ") b = a * a print(" The square of ",a ,"is", b)
1
2
3
4
34. How many built-in functions are used in the following code: a = int(input("Enter a number: ") b = a * a print(" The square of ",a ,"is", b)
input( )
tuple( )
print( )
dictionary( )
35. Which of the following is not the type of function argument?
Required argument
Keyword argument
initial argument
default argument
36. Write the output of the following: print("A") def prnt(): print("B") print("C") prnt()
A B C
B C A
A B
A C B
37. Write the output of the following: def check(): i = 5 while i > 1: if i //2==0: x = i + 2 i = i-1 else: i = i-2 x = i print (x) check()
3 3
5 3
3 1
3 2
38. Which module is to be imported for using randint( ) function?
rand
random
randomrange
randomrange
39. Which of the following number can never be generated by the following code: random.randrange(0, 100)
0
100
99
1
40. Write the output of : print(abs(-45))
45.0
-45
45
None of the above
41. Write the output of : print(max([1, 2, 3, 4], [4, 5, 6], [7]))
[1, 2, 3, 4]
[4, 5, 6]
[7]
7
42. Write the output of : print(min(tuple(“computer”)))
c
o
u
t
43. Choose the incorrect statement.
print(pow(2, 3))
print(pow(2.3, 3.2))
print(pow(2, 3, 2))
None of the above
44. Which of the following return floating point number?
print(pow(2, 3))
print(pow(2.3, 3.2))
print(pow(2, 3, 2))
All the above
45. A Python standard library consists of a number of modules
A Python standard library consists of a number of modules
Library and modules are alias of each other.
A Module consists of a number of Python standard libraries
None of the above
46. Arrange the following from Simple(small) to Complex(big). Instructions, Functions, Library, Module
Instructions, Functions, Library, Module
Functions, Instructions, Library, Module
Module, Functions, Instructions, Library
Instructions, Functions, Module, Library
47. A module is save with extension ____________
.py
.pym
.mpy
.mps
48. Choose the correct statement to import Math module:
Import math
import math
import Math
Import Math
49. Which of the following is not built-in module in python?
math
random
statistics
arithmetic
50. In math.ceil(x), what is x here?
An Integer
A Floating point number
An integer or floating point number
None of the above
51. Write the output of the following : print(math.floor(-4.5))
-4
-5
4
5
52. Write the output of : print(math.fabs(-6.7))
-6
6.7
-6.7
7
53. _______ function of math module calculates the factorial.
fact( )
facto( )
factorial( )
factor( )
54. Which of the following function return random real number (float) in the range 0.0 to 1.0?
random( )
randint( )
randrange( )
None of the above
55. Smallest number return by statement random.randrange(2,7) is _______
2
7
-2
0
56. Which of the following function is not defined in statistics module?
mean( )
mode( )
median( )
sqrt( )
57. In order to get a list of modules available in Python, we can use the __________ statement:
help(“module”)
list(“module”)
available(“module”)
show(“module”)
58. Aman wants to import only sqrt( ) function of math module. Help him to write the correct code.
import math
from math import sqrt
import sqrt from math
import sqrt
59. Which of the following options can be the output for the following code? import random List=["Delhi","Mumbai","Chennai","Kolkata"] for y in range(4): x = random.randint(1,3) print(List[x],end="#")
Delhi#Mumbai#Chennai#Kolkata#
Mumbai#Chennai#Kolkata#Mumbai#
Mumbai#Chennai#Kolkata#Mumbai#
Mumbai# Mumbai #Chennai # Mumbai
60. What will be the output of the following code? x = 3 def myfunc(): global x x+=2 print(x, end=' ') print(x, end=' ') myfunc() print(x, end=' ')
3 5 5
5 5 5
5 3 5
3 3 5
61. Which of the following components are part of a function header in Python? i. function name ii. return statement iii. parameter list iv. def keyword
only i
i and iii
iii and iv
i, iii and iv
62. Which of the following function headers is correct?
def cal_si(p=100, r, t=2):
def cal_si(p=100, r=8, t):
def cal_si(p, r=8, t):
def cal_si(p, r=8, t=2):
63. Which of the following is the correct way to call a function?
my_func( )
def my_func( )
return my_func
call my_func( )
64. What will be the output of the following Python code? def add (num1, num2): sum = num1 + num2 sum = add(20,30) print(sum)
50
0
Null
None
65. 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())
100 200
150 300
250 75
250 300
66. What will be the output of the following code? 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)
50#50
50#5
50#30
5#50#
67. 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="#")
5#8#15#4#
5#8#5#4#
5#8#15#14#
. 5#18#15#4#
68. What will be the possible outcome of the following code: import random X =[1,2,3,4] m = random.randint(0,3) for i in range(m): print (X[i],"--",end=" ")
1 —
1 — 2 —
1 — 2 — 3 —
All the above
69. Write the output of the following code : import random for i in range(random.randint(2, 2)): print(i)
0 1
1 2
0 1 2
Generate different number
70. Write the output of the following code : import random for i in range(random.randint(2,3)): print("A")
A A
A A A
A A OR A A A
Error
71. What is the minimum and maximum value of ‘A’ in the following statement. import random A=random.randint(2,30) print(A)
3 and 30
2 and 30
2 and 29
2 and 28
72. Write the output of the following code : import random A=random.randrange(20) print(A)
Any number between 0 to 19 (including both)
Any number between 0 to 20 (including both)
Any number between 1 to 20 (including both)
None of the above
73. Write the output of the following code : import random print(int(random.random( )))
Any random number less than 1 and greater than 0
Always generate 0
Always generate 1
Shows Error
74. Write the output of the following code : import random print(int(random.random()*5))
Always generate 0
Generate any number between 0 to 4 (including both)
Generate any number between 0 to 5 (including both)
None of the above
75. Which of the following subject will never printed in following code? import random L=["English", "Hindi", "Math", "Science", "SST", "CS", "IP"] for i in range(random.randint(1, 6)): print(L[i])
CS and IP both
English
IP
English and Hindi both
76. What is the minimum and maximum value of ‘v’ in the following statement. import random v=random.randrange(20)-3 print(v)
0,19 b.
0,17
3,16
-3,17
77. Which of the following method is not included in random module?
Shuffle( )
randrange( )
randomrange( )
uniform( )
78. A = random._______________([1,2,3,4,5]). Fill in the blank so that ‘A’ may have any value from the list.
shuffle
choice
uniform
None of the above
79. Functions created by user is called _____________ function
Inbuilt
Library
User defined
logical
80. Division of large programs into smaller programs. These smaller programs are called ____
Functions
Operators
logical programs
specific programs
81. Use of functions _______________ the size of programs.
increases
reduces
makes no change in
None of the above
82. A function can be called __________ times in a program.
3
7
4
any number of
83. Which of the following is not a type conversion functions?
int( )
str( )
input( )
float( )
84. Write the output of the following. print(int( ))
Error
Any random number
0
1
85. Which of the following statement will return error? print(int("a")) #Statement1 print(str(123)) #Statement2
Statement1
Statement2
Statement3
Statement4
Submit