MCQ Function File Handling Python Review
MCQ Function File Handling Python Review
dic1={‘r’:’red’,’g’:’green’,’b’:’blue’}
for i in dic1:
print (i,end=’’)
print(4 + 3**3/2)
6.Which of the following mode, file should be open if we want to add new
7.TO sort the rows of the result table, the ORDER BY clause is specified.
(a) math.pow(a,b) (b) a**b (c) both a and b are correct (d) math.sqrt(a,b)
10.Which of the following statement(s) would give an error after executing the following code?
print(S) # Statement 2
11.To use function of any module, we have to use import keyword (command)
13.When you use multiple type argument in function then default argument take place
(a) At beginning (b) At end (c) Anywhere (d) None of the above
14.Harsh has written a code to input a number and find a table of any number. His code is having
errors. Rewrite the correct code and underline the corrections made.
def table():
for i in range(1,11):
table()
“In Python, when the value of a variable changes, its id changes also”.
z=str.split()
newstr="=".join([z[2].upper(),z[3],z[2]+z[3],z[1].capitalize()])
20.Which of the following can be used to read the next line from a file object fobj?
21.Identify the missing statement of the following python code if the output produced is 500:
a=100
def show( ):
global a
a=100
def invoke( ):
a=500
show( )
invoke( )
print(a)
22.The <filehandle>.seek( 8 ) if applied to a text file stream object moves the read cursor /
pointer :
23.Look at the code below and identify the type of exception that will be thrown from the options
arr=[10,20,30,40,50,60,70,80,90,100]
for i in range(len(arr)+1):
print(arr.pop())
The explicit conversion of an operand to a specific type is called (a)Type casting (b) coercion
(c) translation (d) None of these
25.Which of the following is not a core data type in Python? (a)Lists (b) Dictionaries (c)Tuple (d)
Class
dict={"Exam":"AISSCE", "Year":2022}
dict.update({"Year”:2023} )
will be deleted
(a) Year . 0. at All the best (b) Year 0. at All the best
(c) Year . 022. at All the best(d) Year . 0. at all the best
29.Which of the following mode will refer to binary data? (a)r (b) w (c) + (d) b
30.Which of the following statement(s) would give an error after executing the following code?
seek.file_object(offset)
32.Keywords are the reserved words used by a python interpreter to recognize the structure of a
program
33.Consider the statements given below and then choose the correct output from
the given options:
print(crick[-1:4:-2])
import random
NUMBER=random.randint(0,3)
N=5
while STRING[N]!="L":
NUMBER=NUMBER+1
N=N-1
def fun(a):
a=10
print(a)
a=5
fun(a)
print(a)
Python throws errors and exceptions when the code goes wrong, which may cause the
program to stop abruptly.
40. Whatwillbetheoutputofthefollowingcode?
a) {4:’Four’,5:‘Five’}
b) Methodupdate()doesn’texistfordictionary
c) {1:“One”,2:“Two”,3:“C”}
d) {1:“One”,2:“Two”,3:“C”,4:‘Four’,5:‘Five’}
41 EvaluatetheexpressiongivenbelowifA=16andB=15.
A%B//A
a) 1 b)0.0 c)0 d)1.0
42 Selectthecorrectoutputofthefollowingcode:
a) [I#N#F#O#R#M#A#T#I#C#S]
b) [‘I’,‘N’,‘F’,‘O’,‘R’,‘M’,‘A’,‘T’,‘I’,‘C’,‘S’]
c) [‘INFORMATICS’]
d) [‘INFORMATICS’]
43.Whichof the following are themodes of both writing and reading in binary
formatin file?
a) wb+
b) w
c) w+
d) wb
44.Which of the following statement(s) would give an error after executing the
following code?
statement1
statement2
statement3
statement4
ii. myfile=open('student.txt','w')
iii. myfile=open('student.txt','r')
iv. myfile=open('student.txt')
a) onlyi
b) bothiandiv
c) bothiiiandiv
d) bothiandiii
print (5 + 3 ** 2 / 2)
51.Consider the list aList=[ “SIPO”, [1,3,5,7]]. What would the following code
print?
(a) S, 3 (b) S, 1 (c) I, 3 (d) I,
1
52.Which of the following mode in the file opening statement creates a new file if
the file
MyTuple1=(1, 2, 3) #Statement1
MyTuple2=(4) #Statement2
MyTuple1.append(4) #Statement3
54.The correct statement to place the file handle fp1 to the 10th byte from the
current
position is:
55.Suppose str1= ‘welcome’. All the following expression produce the same result
except one.
Which one?
(a) str[ : : -6] (b) str[ : : -1][ : : -6] (c) str[ : :6] (d) str[0] + str[-1]
>>>str1.split(‘a’)
a) [‘India’,’is’,’a’,’Great’,’Country’]
a) w b) a+ c) ab d) r
print(mySubject[:3] + mySubject[3:])
a) Com b) puter Science
a) <objectvariable> = pickle.load(<fileobject>)
b) pickle.load(<fileobject>, <objectvariable>)
c) <fileobject>.load(<objectvariable>)
d) <objectvariable> = <fileobject>.load( )
2 + 9 * ( ( 3 * 12) – 8 ) / 10
Q17 and 18 are ASSERTION AND REASONING based questions. 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 the correct explanation for A
Python does not allow the same variable to hold different data literals / data types.
66.What should be the data type for the column Price storing values less than
₹1000, eg: 200.21?
z=str.split()
newstr="=".join([z[2].upper(),z[3],z[2]+z[3],z[1].capitalize()])
dict_fruit={"Kiwi":"Brown", "Cherry":"Red"}
dict_vegetable={"Tomato":"Red", "Brinjal":"Purple"}
c) dict_fruit.add(dict_vegetable) d) dict_fruit.merge(dict_vegetable)
print(tup1[5:-1]) # Statement 1
print(tup1[5]) # Statement 2
print(tup1[5:]) # Statement 3
print(tup1[-4:8]) # Statement 4
import random
arr=['10','30','40','50','70','90','100']
L=random.randrange(1,3)
U=random.randrange(3,6)
for i in range(L,U+1):
print(arr[i],"$",end="@")
d) 40 $@50 $@
x=100
def study(x):
________________ # statement 1
x=50
print(“Value of x is :”, x)
Look at the code below and identify the type of exception that will be
thrown from the options arr=[10,20,30,40,50,60,70,80,90,100]
for i in range(len(arr)+1):
print(arr.pop())
f.write(line+’\n’)
73.Which of the following statements is true regarding the content of the file
‘readme.txt’?
a) Both strings of list lines will be written in two different lines in the file
‘readme.txt’
. b) Both strings of list lines will be written in the same line in the file ‘readme.txt’.
c) string 1 of list lines will overwrite string 2 of list lines in the file ‘readme.txt’.
d) string 2 of list lines will overwrite string 1 of list lines in the file ‘readme.txt’.
(a)
dict_fruit.update(dict_vegetable)
(c) dict_fruit.add(dict_vegetable)
(d) dict_fruit.mere(dict_vegetable)
76.Considerthe given
expression:
count= 0
while (True):
ifcount % 3 == 0:
if(count >15):
break;
count+= 1
importrandom
points=[20,40,10,30,15]
points=[30,50,20,40,4
5]
begin=random.randint(1,
3)
last-random.randint(2,4) for c in
range(begin,last+1
):
print(points[c],"#")
(a)
20#50#30#
(c)
50#20#40#
(b) 20#40#45
(d) both(b)
and
print(16-(3+2)*5+2**3*4)
(a) 54
(b) 46
(c) 23
(d) 32
try:
a=10
b=0
print('result=',a/b)
exceptException as
error:
print(error)
else:
print('No error')
message="Bring it
on!!!"
"Motivation"
print(book_dict.items())
84.AddapairofparenthesestoeachexpressionsothatitevaluatestoTrue.
a) 2+3==4+5==7 b)0==1 ==2
85.Whatwillbeoutputofthefollowingst
atement? S='W for Wisdom'
print(S[2:-2:2])
86.Whichofthe following is
akeywordin Python?
87.Giventhefollowingdictionaries:
dict_student={"rno":"53","name":‘Rajve
erSingh’} dict_marks = {"Accts" : 87,
"English" : 65}
88.Whichstatementwillmergethe contentsofbothdictionaries?
c)dict_student.merge(dict_marks) d)dict_student.update(dict_marks)
89.Whichofthefollowingstatement(s)wouldgiveanerrorafterex
ecutingthe following code?
EM=“BlueTickwillcost$8” #Statement 1
print(EM) #Statement 2
(a)Statement3 (b)Statement 4
(c)Statement5 (d)Statement4and5
90.Whichofthefollowingstatement(s)wouldgiveanerrorafterexecutingth
efollowing code?
D={'Rno':32,'Name':'Archana','Subject':
['Physics','Maths',’CS'],'Marks':(85,75,89)} #S1 print(D) #S2
D[‘Subject’][2]=’Chemistry’ #S3
D[‘Marks’][2]=98 #S4
91.Considerthefollowingexpression:not((TrueandFalse)orTr
ueandFalse) What would it return?
92.Selectthecorrectoutputoft
hecode:
for i in "QUITE":
print([i.lower()],end="#")
a) q#u#i#t#e# b) [„quite#‟]
c)['q']#['u']#['i']#['t']#['e']# d)[„quite‟]#
93.Identifythemostpossibleoutput(s)onexecutionofthefollowing
statement: import random as rd
Lang=[‘Python’,’Java’,’R
uby’,’C++’] myNum =
random.randint(0,3)
94.for I in range(1,myNum):
print(Lang[I],end=’%’)
95.Choosethecorrectpossibleoutputonexecutionofthefollowing
statement: S='Teach to reach'
L=S.split() X='@'.join([L[0].replace('ch','m').upper(),L[2]
[:3].capitalize(),L[2][1::].title()]) print(X)
b) Team@REA@EACH b)TEAM@Rea@Each
c)TEAM@Rea@EACH d)TEAM@rea@Each