0% found this document useful (0 votes)
74 views16 pages

MCQ All For Test

This document contains multiple-choice questions (MCQs) related to Python programming, covering topics such as basic I/O, operators, flow of execution, string methods, and list operations. Each question is worth one mark and includes options for answers. Additionally, the document provides a set of answers for the questions listed.

Uploaded by

Palak Soni
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)
74 views16 pages

MCQ All For Test

This document contains multiple-choice questions (MCQs) related to Python programming, covering topics such as basic I/O, operators, flow of execution, string methods, and list operations. Each question is worth one mark and includes options for answers. Additionally, the document provides a set of answers for the questions listed.

Uploaded by

Palak Soni
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
You are on page 1/ 16

MCQ PYTHON By Gajendra Sir Mo. No.

: 9810301034
MCQ CS 083 PYTHON
Set 1
All questions are of 1 mark.
BASIC IOP & OPERATORS
1. Which of the following is a valid identifier: i. >>>not -5 ii. >>>not 5 iii. >>>not 0 iv. >>>not(5-
i. 9type ii. _type iii. Same-type iv. True 1)
2. Which of the following is a relational operator: 13. Give the output of the following code:
i. > ii. // iii. or iv. ** >>>7*(8/(5//2))
3. Which of the following is a logical operator: i. 28 ii. 28.0 iii. 20 iv. 60
i. + ii. /= iii. and iv. in 14. Give the output of the following code: >>>import
4. Identify the membership operator from the math
following: >>> math.ceil(1.03)+math.floor(1.03)
i. in ii. not in iii. both i & ii iv. Only i i. 3 ii. -3.0 iii. 3.0 iv. None of the
5. Which one is a arithmetic operator: above
i. not ii. ** iii. both i & ii iv. Only ii 15. What will be the output of the following code:
6. What will be the correct output of the statement : >>>import math ;>>>math.fabs(-5.03)
>>>4//3.0 i. 5.0 ii. 5.03 iii. -5.03 iv . None of the
i. 1 ii. 1.0 iii 1.3333 iv. None of the above
above 16. Single line comments in python begin with……..
7. What will be the correct output of the statement : symbol.
>>> 4+2**2*10 i. # ii. “ iii. % iv. _
i. 18 ii. 80 iii. 44 iv. None of the 17. Which of the following are the fundamental building
above block of a python program.
8. Give the output of the following code: i. Identifier ii. Constant iii. Punctuators iv.
>>> a,b=4,2 ;>>> a+b**2*10 Tokens
i. 44 ii. 48 iii. 40 iv. 88 18. The input() function always returns a value of
9. Give the output of the following code: …..type.
>>> a,b = 4,2.5 ; >>> a-b//2**2 i. Integer ii. float iii. string iv.
i. 4.0 ii. 4 iii. 0 iv. None of the above Complex
10. Give the output of the following code: 19. ……….. function is used to determine the data type of
>>>a,b,c=1,2,3 ;>>> a//b**c+a-c*a a variable.
i. -2 ii. -2.0 iii. 2.0 iv. None of the above i. type( ) ii. id( ) iii. print( ) iv. str( )
11. If a=1,b=2 and c= 3 then which statement will give 20. The smallest individual unit in a program is known as
the output as : 2.0 from the following: a..
i. a%b%c+1 ii. a%b%c+1.0 iii. a%b%c iv. a%b%c-1 i. Token ii. keyword iii. punctuator iv. identifier
12. Which statement will give the output as : True from
the following :
FLOW OF EXECUTION
21.Which of the following is not a decision making while a>0: print(a)
statement print(“Bye”)
i. if..else statement ii. for statement iii. if-elif i. times ii. Once iii. Infinite iv. None of these
statement iv. if statement 24.What abandons the current iteration of the loop
22.…………loop is the best choice when the number of i. continue ii. stop iii. infinite iv. Break
iterations are known. 25.Find the output of the following python program
ii. while ii. do-while iii. for iv. None of for i in range(1,15,4): print(i, end=’,’)
these i. 1,20,3 ii. 2,3,4 iii. 1,5,10,14 iv. 1,5,9,13
23. How many times will the following code be 26.…………loop is the best when the number of iterations
executed. are not known.
a=5
Page 1 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
i. while ii. do-while iii. for iv. None of 29.How many times will the following code be executed
these for i in range(1,15,5):
27.In the nested loop ……………..loop must be terminated print(i,end=’,’)
before the outer loop. i. 3 ii. 4 iii. 1 iv. infinite
i. Outer ii. enclosing iii. inner iv. None of 30.Symbol used to end the if statement:
these i. Semicolon(;) ii.Hyphen(-) iii. Underscore( _ ) iv.
28.…………..statement is an empty statement in python. colon(:)
i. pass ii. break iii. continue iv. if

STRING METHODS AND BUILT-IN FUNCTIONS


31. Which of the following is not a python legal string i. True ii. False
operation. iii. None iv.
i. ‘abc’+’aba’ ii. ‘abc’*3 iii. ‘abc’+3 iv. Error
‘abc’.lower() 40. What will be the output
32. Which of the following is not a valid string of the following code.
operation. Str=”python 38”
i. Slicing ii. concatenation iii. Repetition iv. print(Str.isalnum())
floor i. True ii. False iii.
33. Which of the following is a mutable type. None iv. Error
i. string ii. tuple iii. int iv. list 41. What will be the output
34. What will be the output of the following code of the following code.
str1=”I love Python” Str=”pyThOn”
strlen=len(str1)+5 print(Str.swapcase())
print(strlen) i. PYtHoN ii. pyThon iii. python iv.
i. 18 ii. 19 iii. 13 iv. 15 PYTHON
35. Which method removes all the leading 42. What will be the output
whitespaces from the left of the string. of the following code.
i. split() ii. remove() iii. lstrip() iv rstrip() Str=”Computers”
36. It returns True if the string contains only print(Str.rstrip(“rs”))
whitespace characters, otherwise returns False. i. Computer ii. Computers iii. Compute iv.
i) isspace() ii. strip() iii. islower() iv. isupper() compute
37. It converts uppercase letter to lowercase and vice 43. What will be the output
versa of the given string. of the following code.
Str=”This is Meera\’ pen”
i. lstrip() ii. swapcase() iii. istitle() iv. count()
print(Str.isdigit())
38. What will be the output of the following code. i. 21 ii. 20 iii. 18 iv. 19
Str=’Hello World! Hello Hello’
44. How many times is the word ‘Python’ printed in
Str.count(‘Hello’,12,25) the following statement.
i. 2 ii. 3 iii. 4 iv. 5
s = ”I love Python”
39. What will be the output for ch in s[3:8]:
of the following code.
print(‘Python’)
Str=”123456” i. 11 times ii. 8 times iii. 3 times iv. 5
print(Str.isdigit()) times

Page 2 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
45. Which of the following i. [“Computer”,”Science”] iii.
is the correct syntax of string [“Comput”,”Science”] ii. [“Comput”,”erScience”] iv.
slicing: [“Comput”,”er”,”Science”]
i. str_name[start:end] iii. str_name[start:step] 48. Following set of
ii. str_name[step:end] iv. commands are executed in
str_name[step:start] shell, what will be the output?
46. What will be the output >>>str="hello"
of the following code? >>>str[:2]
A=”Virtual Reality” i. he ii. lo iii. olleh iv. hello
print(A.replace(‘Virtual’,’Augmented’)) 49. ………..function will
i. Virtual Augmented iii. Reality always return tuple of 3
Augmented ii. Augmented Virtual iv. elements.
Augmented Reality i. index() ii. split() iii. partition() iv. strip()
47. What will be the output 50. What is the correct python code to display the
of the following code? last four characters of
print(“ComputerScience”.split(“er”,2)) str=“Digital India”
i. str[-4:] ii. str[4:] iii. str[*str] iv. str[/4:]

NOTES

ANSWERS
1 ii 2 i 3 iii 4 iii 5 iv 6 ii 7 iii
8 i 9 i 10 i 11 ii 12 iii 13 ii 14 i
15 iii 16 i 17 i 18 iii 19 i 20 i 21 ii
22 iii 23 iii 24 iv 25 iv 26 i 27 iii 28 i
29 i 30 iv 31 iii 32 iv 33 iv 34 i 35 iii
36 i 37 ii 38 i 39 i 40 ii 41 i 42 iii
43 iv 44 iv 45 i 46 iv 47 iii 48 i 49 iii
50 i
Page 3 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
MCQ CS 083 PYTHON
Set 2
All questions are of 1 mark.
LIST
51. Given the list L=[11,22,33,44,55], write the output of 60. Match the columns: if
print(L[: :-1]). >>>l=list(‘computer’)
i. [1,2,3,4,5] ii. [22,33,44,55] Column A Column B
iii. [55,44,33,22,11] iv. Error in code 1. L[1:4] a. [‘t’,’e’,’r’]
52. Which of the following can 2. L[3:] b. [‘o’,’m’,’p’]
add an element at any index in 3. L[-3:] c. [‘c’,’o’,’m’,’p’,’u’,’t’]
the list? 4. L[:-2] d. [‘p’,’u’,’t’,’e’,’r’]
i. insert( ) ii. append( ) iii. extend() iv. all of these i. 1-b,2-d,3-a,4-c iii. 1-c,2-b,3-a,4-d
53. Which of the following function will return a list ii. 1-b,2-d,3-c,4-a iv. 1-d,2-a,3-c,4-b
containing all the words of the given string? If a list is created as l=[1,2,3,’a’, [‘apple’,’green’], 5,6,7,
i . split() ii. index() i [‘red’,’orange’]]
i i . count() iv. list() then what will be the output of the following
statements:
54.Which of the following statements are True.
61. >>>l[4][1]
a. [1,2,3,4]>[4,5,6]
i. ‘apple’ ii. ‘red’ iii. ‘green’ iv. ‘orange’
b. [1,2,3,4]<[1,5,2,3]
62. If >>>l[8][0][2]
c. [1,2,3,4]>[1,2,0,3] i. ‘d’ ii. ‘r’ iii. ‘e’ iv. ‘o’
d. [1,2,3,4]<[1,2,3,2] 63. >>>l[-1]
i. a,b,d ii. a,c,d iii. a,b,c iv. Only d
i. [‘apple’,’green’] iii. [‘red’,’orange’] ii. [‘red’
55. If l1=[20,30] l2=[20,30] l3=[‘20’,’30’] l4=[20.0,30.0] ] iv. [’orange’]
then which of the following statements will not return 64 >>>len(l)
‘False’: i. 10 iii. 9 ii. 8 iv 11
a. >>>l1==l2 b. >>>l4>l1 c. >>>l1>l2 d. >>> l2==l2 65. What will be the output of the following code:
i. b, c ii. a,b,c iii. a,c,d iv. a,d >>>l1=[1,2,3]
56. If >>>l1=[10,20,30,40,50] >>>l1.append([5,6])
>>>l2=l1[1:4] >>>l1
What will be the elements of list l2: i. [1,2,3,5,6] ii. [1,2,3,[5,6]] iii. [[5,6]] iv. [1,2,3,[5,6]]
i. [10,30,50] ii. [20,30,40,50] iii. [10,20,30] iv. 66. What will be the output of the following code:
[20,30,40] >>>l1=[1,2,3]
57. >>>l=[‘red’,’blue’] >>>l = l + ‘yellow’ >>>l2=[5,6]
What will be the elements of list l: >>>l1.extend(l2)
i. [‘red’,’blue’,’yellow’] ii. [‘red’,’yellow’] iii. >>>l1
[‘red’,’blue’,’yellow’] iv. Error i. [5,6,1,2,3] ii. [1,2,3,5,6] iii. [1,3,5] iv. [1,2,3,6]
58. What will be the output of the following 67. What will be the output of the following code:
code: >>>l1=[1,2,3]
>>>l=[1,2,3,4] >>>l1.insert(2,25)
>>>m=[5,6,7,8] >>>l1
>>>n=m+l i. [1,2,3,25] ii. [1,25,2,3] iii. [1,2,25,3] iv. [25,1,2,3,6]
>>>print(n)
68. >>>l1
i. [1,2,3,5,6,7,8] ii. [1,2,3,4,5,6,7,8] iii. [1,2,3,4][5,6,7,8]
=[10,20,3
iv. Error
0,40,50,60
59. What will be the output of the following code: ,10,20,10]
>>>l=[1,2,3,4] >>>l1.cou
>>>m=l*2 nt(‘10’)
>>>n=m*2 i. 3 ii. 0 iii. 2 iv. 9 69.
>>>print(n)
69. Which operators can be used with list?
i [1,2,3,4,1,2,3,4,1,2,3,4]
i. in ii. not in iii. both (i)&(ii) iv. Arithmetic operator only
ii. [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4]
iii. [1,2,3,4][4,5,6,7] iv. [1,2,3,4]
Page 4 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
70. Which of the following function will return the first i. sort() ii. value() iii. index() iv. sorted()
occurrence of the specified element in a list.

Tuple Functions & Dictionary


71. Which of the statement(s) is/are correct. 85 Which of the following statements are not correct:
i. Python dictionary is an ordered collection of items. a. An element in a dictionary is a combination of key-
ii. Python dictionary is a mapping of unique keys to value pair
values b. A tuple is a mutable data type
iii. Dictionary is mutable. c. We can repeat a key in dictionary
iv. All of these. d. clear( ) function is used to deleted the dictionary.
72. ………function is used to convert a sequence data type i. a,b,c ii. b,c,d iii. b,c,a iv. a,b,c,d
into tuple. 86 Which of the following statements are correct:
i. List() ii tuple() iii TUPLE iv. tup() a. Lists can be used as keys in a dictionary
73. It tup=(20,30,40,50), which of the following is b. A tuple cannot store list as an element
incorrect c. We can use extend() function with tuple.
i. print(tup[3]) ii. tup[2]=55 iii. print(max(tup)) iv. d. We cannot delete a dictionary once created.
print(len(tup)) i. a,b,c ii. b,c,d iii. b,c,a iv. None of these
74. Consider two tuples given below: 87 Like lists, dictionaries are……………..which mean they
>>>tup1=(1,2,4,3) can be changed.
>>>tup2=(1,2,3,4) i. Mutable ii. immutable iii. variable iv.
What will the following statement print(tup1<tup2) None of these
i. True ii. False iii. Error iv. None of these 88 To create an empty dictionary , we use
75. Which function returns the number of elements in i. d=[ ] ii. d =( ) iii. d = {} iv. d= < >
the tuple 89 To create dictionary with no items , we use
i. len( ) ii. max( ) iii. min( ) iv. count( ) ii. Dict ii. dict( ) iii. d = [ ] iv. None of these
76. Which function is used to return a value for the given 90 What will be the output >>>d1={‘rohit’:56,”Raina”:99}
key. >>>print(“Raina” in d1)
i. len( ) ii. get( ) iii. keys( ) iv. None of these i. True ii. False iii. No output iv. Error
77. Keys of the dictionary must be 91 Rahul has created the a tuple containing some
i. similar ii. unique iii. can be similar or unique iv. numbers as
All of these >>>t=(10,20,30,40)
78. Which of the following is correct to insert a single now he wants to do the following things help him
element in a tuple . 1. He want to add a new element 60 in the tuple, which
i. T=4 ii. T=(4) iii. T(4,) iv. T=[4,] statement he should use out of the given four.
79. Which of the following will delete key-value pair for i. >>>t+(60) ii. >>>t + 60 iii. >>>t +
key=’red’ form a dictionary D1 (60,) iv. >>>t + (‘60’)
i. Delete D1(“red”) ii. del. D1(“red”) iii. del 92 Rahul wants to delete all the elements from the tuple,
D1[“red”] iv. del D1 which statement he should use
80. Which function is used to remove all items form a i. >>>del t ii. >>>t.clear() iii. >>>t.remove() iv.
particular dictionary. >>>None of these
i. clear( ) ii. pop( ) iii. delete iv. rem( ) 93 Rahul wants to display the last element of the tuple,
81. In dictionary the elements are accessed through which statement he should use
i. key ii. value iii. index iv. None of these i. >>> t.display() ii. >>>t.pop() iii. >>>t[-1] iv. >>>t.last()
82. Which function will return key-value pairs of the 94 Rahul wants to add a new tuple t1 to the tuple t,
dictionary which statement he should use
i. >>>t+t1 ii. >>>t.add(t1)
i. key( ) ii. values( ) iii. items( ) iv. get( )
iii. >>>t*t1 iv. None of
83 Elements in a tuple can be of ………….type.
these
i. Dissimilar ii. Similar iii. both i & ii iv. None of
95 Rahul has issued a statement after that the tuple t is
these
replace with empty tuple, identify the statement he had
84 To create a dictionary , key-value pairs are separated
issued out of the following:
by…………….
i. >>> del t ii. >>>t= tuple() iii.
i. (;) ii. ( , ) iii. (:) iv. ( / ) >>>t=Tuple() iv. >>>delete t
Page 5 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
96 Rahul wants to count that how many times the 1. >>>tuple([10,20,30]) a. >>> (10,20,30)
number 10 has come: 2. >>>(“Tea”,)* 3 b. >>> 2
i. >>>t.count(10) ii. >>>t[10] iii. 3. >>>tuple(“Item”) c. >>> ('Tea', 'Tea',
>>>count.t(10) iv. None of these 'Tea') 4.
97 Rahul want to know that how many elements are 4. >>>print(len(tuple([1,2]))) d. >>> ('I', 't', 'e', 'm')
there in the tuple t, which statement he should use out of i. 1-b,2-c,3-d,4-a ii. 1-a,2-
the given four c,3-d,4-b iii. 1-c,2-d,3-a,4-a
i. >>>t.count() ii. >>>len(t) iii. >>>count(t) iv. 1-d,2-a,3-b,4-c
iv. >>>t.sum() 100 Write the output of the following code:
98 >>>t=(1,2,3,4) >>>d={‘name’:’rohan’,’dob’:’2002-03-11’,’Marks’:’98’}
Write the statement should be used to print the first >>>d1={‘name’:‘raj’) >>>d1=d.copy() >>>print(“d1 :”d1) i.
three elements 3 times d1 : {'name': 'rohan', 'dob': '2002-03-11', 'Marks':
i. >>>print(t*3) ii. >>>t*3 iii. '98'} ii. d1 = {'name': 'rohan', 'dob': '2002-03-11',
>>>t[:3]*3 iv. >>>t+t 'Marks': '98'} iii. {'name': 'rohan', 'dob': '2002-03-11',
99 Match the output with the statement given in column 'Marks': '98'} iv. (d1 : {'name': 'rohan', 'dob': '2002-
A with Column B 03-11', 'Marks': '98'})

NOTES

ANSWERS
51 iii 52 i 53 i 54 iii 55 iv 56 iv
57 iv 58 ii 59 ii 60 i 61 iii 62 i 63 iii
64 iii 65 iv 66 ii 67 iii 68 ii 69 iii 70 iii
71 iv 72 ii 73 ii 74 ii 75 i 76 ii 77 ii
78 iii 79 iii 80 i 81 i 82 iii 83 iii 84 iii
85 ii 86 iv 87 i 88 iii 89 ii 90 i 91 iii
92 i 93 iii 94 i 95 ii 96 i 97 ii 98 iii
99 ii 100 i

Page 6 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
MCQ CS 083 PYTHON
Set 3
All questions are of 1 mark.
FUNCTION
101 A function in python begins with which keyword? 112 What is a variable defined inside a function referred
i. void ii. return iii. int iv. def to as?
102 Name the statement that sends back a value from a i. A global variable ii. A volatile variable iii. A local
function : i print ii. input iii. return iv. None variable iv. An automatic variable
103 What is the output of the program given below: 113 How many keyword arguments can be passed to a
x=50 functionin a single function call?
def func(x): i. zero ii. one i i i . zero or more iv. one or more
x=2 114 How are required arguments specified in the
func(x) function heading?
print(‘x is now’,x) i. identifier followed by an equal to sign and the default
i. x is now 50 iii. x is now 2 ii. x is now 100 iv. Error value
What is the output of the program given below: ii. identifier followed by the default value within
import random backticks (“)
x = random.random() iii. identifier followed by the default value within square
y= random.randint(0,4) brackets ([ ])
print(int(x),”:”, y+int(x)) iv. identifier 115 What is returned by >>>
i. 0: 0 iii. 2 : 4 ii. 1: 6 iv. 0 : 5 math.ceil(3.4)?
105 def cal(a,b,c): i. 3 ii. 4 iii. 4.0 iv. 3.0
return a*3,b*3,c*3 # return type tuple 116 What is the value returned by
val=cal(10,12,14) >>> math.floor(3.4)
print(type(val)) i. 3 ii. 4 iii. 4.0 iv. 3.0
print(val)
117 What is returned by
i. <class 'tuple'> , [30, 24, 28] iii. <class 'tuple'> , (30,36,42) >>> math.ceil(-3.4)?
ii. <class 'list'> [30,36,42] iv. <class 'list'> , [10,12,14] ii. 3 ii. 4 iii. 4.0 iv. -3
106 What is the output of the expression: round(4.576) 118 What is the value returned by
i. 4.5 ii. 5 iii. 4 iv. 4.6 >>> math.floor(-3.4)
107 What is the output of the function shown below? i. 3 ii. -4 iii. 4.0 iv. 3.0
import math ; abs(math.sqrt(25)) # return type float 119 What is displayed on executing print(math.fabs(-
i. Error ii. -5 iii. 5 iv. 5.0 3.4))?
108 What is the output of the functions shown below? i. -3.4 ii. 3.4 iii. 3 i v . -3
>>>min(max(False,-3,-4), 2,7) 120 What is output of print(math.pow(3, 2))?
i. 2 i i . False iii. -3 iv. -4 i. 9 ii. 9.0 iii. None iv. None of these
109 What are the outcomes of the function shown 121 What is the value of x if x = math.sqrt(4)?
below? i. 2 ii. 2.0 iii. (2, -2) iv. (2.0, -2.0)
>>>x=3 ; >>>eval('x**2') 122 To include the use of functions which are present
i. Error ii. 1 iii. 9 iv. 6 in the random library, we must use the option: i.
110 Which of the following functions does not throw an import random iii. random.h ii. import.random iv.
error? random.random 123 What is the output of the code
i. ord() ii. ord(‘ ‘) iii. ord(”) iv. ord(“”) shown below?
111 What is the output of below program? import random
def say(message, times = 1): random.choice(2,3,4)
print(message * times , end =’ ‘) i. An integer other than 2, 3 and 4 ii. Either 2, 3 or 4
say(‘Hello and’); say('World', 5) iii. Error iv. 3 only
i. Hello andWorldWorldWorldWorldWorld 124 What is the output of the function shown below
ii. Hello and World 5 (random module has already been imported)?
iii. Hello and World,World,World,World,World >>>random.choice('sun')
iv. Hello and HelloHelloHelloHelloHello i. sun ii. u iii. either s, u or n iv. Error

Page 7 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
125 What is the output of the function shown below if i. upper() ii. isupper iii. isupper() iv is_upper()
the random module has already been imported? 134 What will come in place of statement 3:
>>>import random i. [digits] ii. [“digits”] iii. d[“digits”] iv. d[“Digits”]
>>>random.randint(3.5,7) 135 What will come in place of statement 4:
i. Error i. [“Special_chr”] iii. “Special_chr” ii.
ii. Any integer between 3.5 and 7, including 7 D[“Special_chr”] iv. d(“Special_chr”)
iii. Any integer between 3.5 and 7, excluding 7 iv. The 136 What will come in place of statement 5:
integer closest to the mean of 3.5 and 7 i. s ii. S iii. d[“s”] iv. d[s]
126 Which type of elements are accepted by 137 What will come in place of statement 6:
random.shuffle()? i. d[“Upper_case”] iii. [“Upper_case”]
i. strings ii. lists iii. tuples iv. integers ii. d[“s”] iv. d[s]
127 …………keyword is used to define a function. 138 What will come in place of statement 7:
i. Void ii. func iii. def iv. None i. d[“Digits”] iii. d[“digits”] ii. d[“Digit”] iv. d[s]
128 Which of the following statements are True out of 139 The built-in function sin() belongs to which module:
the given below: i. random ii. pandas iii. math iv. numpy
1. More than one value(s) can be returned by a function 140 …………..function returns the smallest integer greater
2. The variable declared inside a function is a Global than the given floating point number.
variable. i. floor() ii. ceil() iii. sqrt() iv CEIL()
3. Once the function is defined , it may be called only 141 …………function will return the largest integer less
once than the given floating point number.
4. A function is used by invoking it i. floor() ii. ceil() iii. sqrt() iv CEIL()
i. 1 & 2 ii. 1 & 4 iii. 2 & 3 iv. 2 & 4 129 142 ………..function returns the length of the object being
Match the columns: passed.
A B i. Length() ii. Len() iii. len() iv. count()
1. max() a. will compute x**y 143 ………..function returns the absolute value.
2. sqrt(x) b. will select a option randomly i. Abs( ) ii. abs( ) iii. absolute( ) iv. None of these
3. choice() c. will return the largest value 144 The range(x) function will generate the series of
4. pow(x,y) d. will compute (x)1/2 numbers from :
i. 1-a,2-b,3-c,4-d iii. 1-c,2-d,3-b,4-a i. Min to max ii. o to x-1 iii. o to x iv. x
ii. 1-d,2-a,3-c,4-b iv. 1-b,2-c,3-d,4-a 145 ……….. function can identify the whitespace in a
130 What will be the output of the following code: given string.
A=1 i. Space( ) ii. isspace( ) iii. Isspace( ) iv. is_space( )
def f (): 146 Consider the statement given below and answer
A=10 the question:
print(A) >>>S=’My name is Ravindra’
i. 1 ii. 10 iii. Error iv. None 131 Which statement will print “True” out of the given :
>>>def Interest(p,c,t=2,r=0.09): i. print(S.isspace( )) ii. print (s.isspace( ))
return p*t*r iii. print(S[2].isspace) iv. print(S[2].isspace( ))
Considering the above defined function which of 147 A variable declared outside all the functions in a
following function call are legal. python program, then mention the statements which are
1. Interest(p=1000,c=5) True in the context of the variable.
2. Interest(r=0.05,5000,3) 1. This variable will have global scope.
3. Interest(500,t=2,r=0.05) 2. This variable will not be accessible from anywhere in
4. Interest(c=4,r=0.12,p=5000) the prog.
i. 1 , 2 and 4 ii. 2 & 3 iii. 1 &4 iv. 3 & 4 3. This variable will have a large lifetime than local
133 Consider the program given in question no.132 and variable.
answer the question from 133 to 138 given below: 4. This variable will be referred as Local variable.
What will come in place of statement 2: i. Only 1&2 ii. Only 1 iii. Only 1&3 iv. Only 3 .

Page 8 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
Answers:

101 iv 102 iii 103 i 104 i 105 iii


106 ii 107 iv 108 ii 109 iii 110 ii 111 i 112 iii
113 iii 114 i 115 ii 116 i 117 iv 118 ii 119 ii
120 ii 121 ii 122 i 123 ii 124 iii 125 ii 126 ii
127 iii 128 ii 129 iii 130 i 131 iii 132 iv 133 iii
134 iv 135 iii 136 i 137 i 138 i 139 iii 140 ii
141 i 142 iii 143 ii 144 ii 145 ii 146 iv 147 iii

Page 9 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
MCQ CS 083 PYTHON
Set 4
All questions are of 1 mark.
Data File Handling (TEXT)
1 Every file has its own identity associated with it. Which is c. File directory d. File link
known as – 19. How to open a text file in read mode only?
a. icon b. extension c. format d. file type a. r b. r+ c. rb+ d. rw+
2 Which of the following is not a known file type? 20. How to open a text file in write and read mode?
a. .pdf b. jpg c. mp3 d.txp a. r+ b. a+ c. wr d. wb
3. In f=open(“data.txt”, “r”), r refers to __________. 21. Syntax for closing a file:
a. File handle b. File object c. File Mode d Buffer a. closefile(<file object>) b. <fileobject>.close()
4. EOL stands for c. <filename>.closer() d. closefile.<fileobject>
a. End Of Line b. End Of List c. End of Lines d.End Of Location 22.Which method can not be used to read from files?
5. Which of the following file types allows to store large data a. read() b. readlines()
files in the computer memory? c. readlines(<filename>) d. readline()
a. Text Files b. Binary Files c.CSV Files d. None of these 23. What does strip() function do?
6. Which of the following file types can be opened with a. Removes the trailing or leading spaces, if any.
notepad as well as ms excel? b. Deletes the file c. Remove the file object
a. Text Files b. Binary Files c. CSV Files d.None of these d. Removes all the spaces between words
7. Which of the following is nor a proper file access mode? 24. readlines() gives the output as
a. close b. read c. write app d. end a. List b. Tuple c. String d. Sets
8. To read 4th line from text file, which of the following 25. When reading a file using the file object, what method is
statement is true? best for reading the entire file into a single string?
a. dt = f.readlines();print(dt[3]) b. dt=f.read(4) ;print(dt[3]) a. readline() b. read_file_to_str()
c. dt=f.readline(4);print(dt[3]) d. All of these c. read() d. readlines()
9 Which of the following function flushes the files implicitly? 26. Which file can open in any text editor and is in human
a. flush() b. close() c. open() d. fflush() readable form?
10. Which of the following functions flushes the data before a. Binary files b. Text files c. Data files d. Video files
closing the file? 27. Which function breaks the link of file-object and the file
a. flush() b. close() c. open() e. fflush() on the disk?
11. In F=open("MyFile.txt") , name of file object is a. close( ) b.open( ) c. tell( ) d. readline( )
a. open b.MyFile.txt c.F d.F=open() 28. Which function reads the leading and trailing spaces
12. Default EOL character in Python. along with trailing newline character ('\n') also while reading
a. ‘\n’ b. ‘\r’ c. ‘’ d. ‘\t’ the line?
13. Which of the following is not a file extension for text files? a. readlines( ) b. readline( ) c. read( ) d. flush( )
a. .txt b. .ini c. .rtf d. .DAT 29. Which mode is used to retain its previous data and
14. What is the first thing to do before performing any allowing to add new data?
functions on a text file? a. write mode b. read mode
a. Import modules b. Open file c. open mode d. append mode
c. Read file d. Print the name of the file 30. Which function forces the writing of data on disc still
15. What is a file object? pending in output buffer?
a. It serves as a link to the file. a. seek( ) b. tell( ) c.flush( ) d. write( )
b. It is a file present in a computer. 31. Syntax for flush( ) function is:
c.A keyword d. A module in python a. <fileOobject>(flush( )) b. flush( ).<fileobject>
16. Which is not a correct file mode for text files? c. <fileObject>.flush( ) d. flush( ).<file-object>
a. a b. ar c. a+ d. r+ 32. Which function returns the entire file content in a list
17. What does the prefix r in front of a string do? where each line is one item of the list?
a. It makes the string a raw string a. readlines( ) b. readline( ) c. Input( ) d. read()
b. It opens the file in read mode 33. Which function is used to remove the given character
c. It converts the file into text file from trailing end i.e. right end?
d. It creates the file if it doesn’t exist a. strip( ) d. remove( ) b. Istrip( ) c. rstrip( )
18. A file object is also known as
a. File handle b. File copy
Page 10 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
34. Sometimes the last lap of data remains in buffer and is c. write() d. writeall()
not pushed onto disk until a __________ operation is 47. What is the correct syntax of open() function?
performed. a. file=open(file_name[,access_mode][,buffering])
a. dump( ) b. close( ) c. load( ) d. open( ) b. fileobject=open(file_name[,access_model][,buffering])
35. The position of a file-pointer is governed by c. fileobject=filename.open()
the_________. d. none of the mentioned
a. File mode b. append mode 48.In file handling, what does means “r”, “a”?
c. write mode d. open mode a. append, read b. read, append
36. In which mode the file must exist already, otherwise c. read, add d. None of the mentioned
python raises an error? 49.The default file open mode is….
a. read mode b. write mode c. binary mode d. None of these a. w b. r+ c. w+ d. r
37. What is the prefix r stands for in file path? 50. What is the difference between r+ and w+ modes?
a. raw string b. read c. write d. append a. In r+ mode, file length truncates to zero.
38. In which mode______ if the file does not exist, then the b. In w+ mode, file length truncates to zero either file
file is created? exists or not. c. No difference
a. read write mode b. read mode c. write mode d. All of these d. Depends on the operating system
39. Which option is correct about this program? 51. A file maintains a __________ which tells the current
f=open(“ss.txt”,”wb”) position in the file where writing or reading will take place.
print(“Name of the file:”,f.name) a. line b. file pointer c. list d. order
f.flush() 52. Which of the following statements is true regarding the
f.close() opening modes of a file?
a. Compilation error b. Runtime error a. While opening a file for reading, if the file does not exist, an
c. No output d. Flushes the file when closing them error occurs.
40. What is the output of the following? b. While opening a file for writing ,if the file does not exist, an
import sys error occurs.
sys.stdout.write(‘Hello\n’) ; sys.stdout.write(‘Python\n’) c. While opening a file for reading, if the file does not exist, a
a. error b. Runtime error c. Hello Python d. Hello Python new file is created.
41. Which function is used to read all the characters in text d. None of the above.
files? 53.To force python to write the contents of file buffer on to
a. read( ) b. readcharacters( ) c. readall( ) d. readchar( ) storage file,........method may be used.
42. Which function is used to read all the lines? a. buffer() b. flush() c. close() d. write()
a. read( ) b. readall( ) c. readlines( ) d. readline( ) 54. Which of the following statements are true?
43. In which format does the readlines( ) function give the a) When you open a file for reading, if the file does not
output? exist, an error occurs.
a. Integer type b. list type c. string type d. tuple type b) When you open a file for writing, if the file does not
44. In which format does the read( ) function give the exist, a new file is created.
output? c) When you open a file for writing, if the file exists, the
a. Integer type b. string type c. list type d. tuple type existing file content is overwritten with the new content.
45. Which function is used to write a list of strings in a file? d) All of the these
a. writestatement() b. writelines() 55. To read the next line of the file from a file object f1, we
c. writefulline() d. writeline() use:
46. Which function is used to write all the characters? a) f1.read(2) b) f1.read() c) f1.readline() d) f1.readlines()
a. writechar() b. writecharacters()

ANSWER KEY
1.B 2.D 3.C 4.A 5.B 6.C 7.A 8.A 9B 10.A 11.C 12.A 13.D 14.B 15.A
16.B 17.A 18.A 19.A 20.A 21.B 22.C 23.A 24.A 25.C 26.B 27.A 28.B 29.D 30.C
31.C 32.A 33.D 34.B 35.A 36.A 37.A 38.C 39.D 40.D 41.A 42.C 43B 44.B 45.B
46.C 47.B 48.B 49.D 50.B 51.B 52.A 53.B 54.D 55.C

Page 11 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
MCQ CS 083 PYTHON
Set 4
All questions are of 1 mark.
Data File Handling (Binary)
Q1. Which of the following commands is used to open a Q9. What is pickle.dump()?
file “c:\temp.txt” in append-mode? a. outfile - a. dump() function is used to store the object data to the
open(“c:/temp.txt”, “a”) file.
b. outfile - open(“c:\\temp.txt”, “rw”) b. It is used to read
c. outfile - open(“c:\temp.txt”, “w+”) c. append
d. outfile - open(“c:\\temp.txt”, “r+”) d. None of these
Q2 What are the binary files used for? Q10. Which one of the following is the correct
a. It is used to store data in the form of bytes. statement?
b. To store data a. pickle import
c. To look folder good b. import - pickle
d. None of these c. import pickle
Q3. What is the function of `rb` mode in binary? d. None of the above
a. Both reading and writing operations can take place. Q11. Which is the valid syntax to write an object onto a
b. File is in only write mode. binary file opened in the write mode?
c. File is created if it does not exist. a. pickle.dump(<object to be written>, <file handle of
d. File must exist otherwise error will be shown. open file>)
Q4. What is the description of `r+b` in binary mode? b. pickle.dump(<file handle of open file>, <object to be
a. read and write written>)
b. write and read c. dump.pickle(<object>, <file handle>)
c. read only d. None of the above
d. none of these Q12. Which method is used for object serialization?
5. What is binary file mode for append? a. Pickling
a. `rb` b. Unpickling
b. `wb` c. None of the above
c. `ab` d. All of the above
d. None of these Q13. Which method of pickle module is used to read
Q6. What is the binary file mode associated with “ file from a binary file?
must exist, otherwise error will be raised and reading a. dump()
and writing can take place”. b. load()
a. read and write c. All of the above
b. write and read d. None of the above
c. read only Q14.Which method is used for object deserialization?
d. append a. Pickling
Q7. What is the process of converting a byte stream b. Unpickling
back to the original structure called? c. All of the above
a. append d. None of the above
b. txt.file Q15.Which of the following is the correct syntax to read
c. Unpickling from a file using load function? a.
d. None of these. pickle.load(<filehandle>)
Q8. Which module is used to store data into python b. <object> - load.pickle(<filehandle>)
objects with their structure? c. <object> - pickle.load(<filehandle>)
a. pickle d. All of the above
b. binary files Q16. Which method of pickle module is used to write
c. Unpickling onto a binary file?
d. None of these a. dump()
Page 12 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
b. load() d. rb
c. All of the above Q19. Which of the following file modes opens a file for
d. None of the above appending and reading in a binary file and moves the
Q17. Which of the following file modes open a file for files pointer at the end of the file if the file already
reading and writing both in the binary file? exists or creates a new file? a. .a
a. r b. .a+
b. rb c. .ab+
c. rwb d. .ab
d. rb+ Q20.Which of the following file modes will not delete
Q18.Which of the following file modes that opens a file the existing data in binary file? a. .wb
for reading and writing both and overwrites the existing b. .w
file if the file exists otherwise creates a new file ? a. w c. .a
b. wb+ d. .ab
c. rwb
ANSWER KEY
1-A 6-A 11-A 16-A
2-A 7-C 12-A 17-D
3-D 8-A 13-B 18-B
4-A 9-A 14-B 19-C
5-C 10-C 15-C 20-D

Page 13 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034

CSV FILES
Q1_________ is a file format which stores records Q7.Observe the following code and fill the blank in
separated by comma. statement1
a. .tsv import csv with _________ as f: #statement1 r =
b. .csv csv.______(f) #statement2 for row in ______:
c. .py #statement3 print(_____) #statement4
d. .bin a. open("data.csv")
Q2.The CSV files can be operated by _______software. b. f=open("data.csv")
a. Spreadsheet c. Both A & B are Correct
b. Notepad d. Both A & B are incorrect
c. MS Excel Q8.Observe the following code and fill the blank in
d. All of the above statement2
Q3.When you read csv file using csv.reader() function it import csv with _________ as f: #statement1 r =
returns the values in _______ object. csv.______(f) #statement2 for row in ______:
a. dictionary #statement3 print(_____) #statement4
b. tuple a. load
c. nested list b. read()
d. sets c. reader()
Q4.CSV module allows to write multiple rows using d. readlines()
____________ function. Q9.Observe the following code and fill the blank in
a. writerows( ) statement3
b. writerow( ) import csv with _________ as f: #statement1 r =
c. writer( ) csv.______(f) #statement2 for row in ______:
d. None of the above #statement3 print(_____) #statement4
Q5.Which of the following parameter needs to be a. f
added with open function to avoid blank row followed b. r
file each row in CSV file? c. r,f
a. delimiter d. None of the above
b. newline Q10.Observe the following code and fill the blank in
c. writer, delimiter statement4
d. file object import csv with _________ as f: #statement1 r =
Q6.which is the correct way to import a csv module? csv.______(f) #statement2 for row in ______:
a. import csv #statement3 print(_____) #statement4
b. from csv import * a. r
c. None of the above b. row
d. Both A & B c. f
d. csv
ANSWER KEY
1.B 2.D 3.C 4.A 5.B
6.D 7.A 8.C 9.B 10.B

Page 14 of 16 Computer Science 083 PYTHON [email protected]


MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034

Accession and Reasoning


1. Amit, a student of class 12th, is learning CSV File Module in Python. During examination, he has been assigned an
incomplete python code (shown below) to create a CSV File 'School.csv' (content shown below). Help him in completing the
code which creates the desired CSV File. CSV File
1, AKASH, XII, A
2, AKRITI, XII, A
3, ISHA, XII, A
4, RASHI, XII, A
5, SEJAL, XII, A
Incomplete Code
import_____ #Statement-1 name = input("Enter Name : ")
fh = open(_____, _____, newline='') #Statement-2 Class = input("Enter Class : ")
stuwriter = csv._____ #Statement-3 section = input("Enter Section : ")
data = [ ] rec = [_____] #Statement-4
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION'] data.append(rec)
data.append(header) for i in range(5): stuwriter. _____ (data) #Statement-5
roll_no = int(input("Enter Roll Number : ")) fh.close()
i. Identify the suitable code for blank space in line marked as b) reader (MyFile)
Statement-1. c) writer (fh)
a) csv file d) writer (MyFile)
b) CSV Correct Answer: c) writer (fh)
c) csv iv. Identify the suitable code for blank space in line marked
d) Csv as Statement-4.
Correct Answer: c) csv a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
ii. Identify the missing code for blank space in line marked as b) ROLL_NO, NAME, CLASS, SECTION
Statement-2? c) 'roll_no','name','Class','section'
a) "School.csv","w" d) roll_no,name,Class,sectionc) co.connect()
b) "Student.csv","w" e) Correct Answer: d) roll_no,name,Class,section
c) "Student.csv","r" v. Choose the function name that should be used in the blank
d) "School.csv","r" space of line marked as Statement-5 to create the desired
Correct Answer: a) "School.csv","w" CSV File? a) dump( )
iii. Choose the function name (with argument) that should be b) load( )
used in the blank pace of line marked as c) writerows( )
Statement-3 d) writerow( )
a) reader (fh) Correct Answer: c) writerows( )
2: Amritya Seth is a programmer, who has recently been given a task to write a python code to perform the following binary
file operations with the help of two user defined functions/modules:
a. AddStudents() to create a binary file called STUDENT.DAT containing student information – roll number, name and
marks (out of 100) of each student.
b. GetStudents() to display the name and percentage of those students who have a percentage greater than 75. In case
there is no student having percentage > 75 the function displays an appropriate message. The function should also display the
average percent.
He has succeeded in writing partial code and has missed out certain statements, so he has left certain queries in comment
lines. You as an expert of Python have to provide the missing statements and other related queries based on the following
code of Amritya. Answer any four questions (out of five) from the below mentioned questions.
import pickle Name = input("Name : ")
def AddStudents(): Percent = float(input("Percent :"))
____________ #1 statement to open the binary file to write L = [Rno, Name, Percent]
data while True: ____________ #2 statement to write the list L
Rno = int(input("Rno :"))
Page 15 of 16 Computer Science 083 PYTHON [email protected]
MCQ PYTHON By Gajendra Sir Mo. No. : 9810301034
into the file Total+=R[2]
Choice = input("enter more (y/n): ") if R[2] > 75:
if Choice in "nN": print(R[1], " has percent = ",R[2])
break F.close() Countabove75+=1
def GetStudents(): except:
Total=0 break
Countrec=0 if Countabove75==0:
Countabove75=0 print("There is no student who has percentage more than
with open("STUDENT.DAT","rb") as F: 75")
while True: average=Total/Countrec
try: print("average percent of class = ",average)
____________ #3 statement to read from the file AddStudents( )
Countrec+=1 GetStudents( )
i. Which of the following commands is used to open the file Correct Answer: a. R = pickle.load(F)
“STUDENT.DAT” for writing only in binary format? (marked as iv. Which of the following statement(s) are correct regarding
#1 in the Python code) the file access modes?
a. F= open("STUDENT.DAT",'wb') a. ‘r+’ opens a file for both reading and writing. File object
b. F= open("STUDENT.DAT",'w') points to its beginning.
c. F= open("STUDENT.DAT",'wb+') b. ‘w+’ opens a file for both writing and reading. Adds at the
d. F= open("STUDENT.DAT",'w+') end of the existing file if it exists and creates a new one if it
Correct Answer: a. F= open("STUDENT.DAT",'wb') does not exist.
ii. Which of the following commands is used to write the list L c. ‘wb’ opens a file for reading and writing in binary format.
into the binary file, STUDENT.DAT? (marked as #2 in the Overwrites the file if it exists and creates a new one if it
Python code) does not exist.
a. pickle.write(L,f) d. ‘a’ opens a file for appending. The file pointer is at the start
b. pickle.write(f, L) of the file if the file exists.
c. pickle.dump(L,F) Correct Answer: a
d. f=pickle.dump(L) v. Which of the following statements correctly explain the
Correct Answer: c. pickle.dump(L,F) function of seek() method?
iii. Which of the following commands is used to read each a. tells the current position within the file.
record from the binary file STUDENT.DAT? (marked as #3 in b. determines if you can move the file position or not.
the Python code) c. indicates that the next read or write occurs from that
a. R = pickle.load(F) position in a file.
b. pickle.read(r,f) d. moves the current file position to a given specified position
c. r= pickle.read(f) Correct Answer: d
d. pickle.load(r,f)
============================

Page 16 of 16 Computer Science 083 PYTHON [email protected]

You might also like