Nothing Special   »   [go: up one dir, main page]

MCQ Function File Handling Python Review

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

1.Identify the invalid Python statement from the following.

(a) _b=1 (b) __b1= 1 (c) b_=1 (d) 1 = _b

2. Identify the valid arithmetic operator in Python from the following.

(a) // (b) < (c) or (d) <>

3.Give the output:

dic1={‘r’:’red’,’g’:’green’,’b’:’blue’}

for i in dic1:

print (i,end=’’)

(a) rgb (b) RGB (c) RBG (d) rbg

4.Predict the correct output of the following Python statement –

print(4 + 3**3/2)

(a) 8 (b) 9 (c) 8.0 (d) 17.5

5.Choose the most correct statement among the following –

(a) a dictionary is a sequential set of elements

(b) a dictionary is a set of key-value pairs

(c) a dictionary is a sequential collection of elements key-value pairs

(d) a dictionary is a non-sequential collection of elements

6.Which of the following mode, file should be open if we want to add new

contents in existing file contents?


(a) a (b) r (c) w (d) None of the above

7.TO sort the rows of the result table, the ORDER BY clause is specified.

8.In the given query which keyword has to be inserted?

INSERT INTO employee _______ (1002, ‘Kausar’,2000)

(a) Table (b) values (c) relation (d) Field

9.Correct statement for ab is

(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?

S="Welcome to VBC" # Statement 1

print(S) # Statement 2

S="Thank you" # Statement 3

S[0]= '$' # Statement 4

S=S+"Thank you" # Statement 5

(a) Statement 3 (b) Statement 4

(c) Statement 5 (d) Statement 4 and 5

11.To use function of any module, we have to use import keyword (command)

before the use of function of a module

12.Which method is used to move the file pointer to a specified position.

(a) tell() (b) seek() (c) seekg() (d) tellg()

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():

n=int(("Enter number which table U need:"))

for i in range(1,11):

print(“Table of Enter no=”,i*i)

table()

15.State True or False

“In Python, when the value of a variable changes, its id changes also”.

16.Which of the following is an invalid identifier in Python?

(a) List (b) sum (c) MyData (d) True

17.What will the following expression be evaluated to in Python?

print( ( - 33 // 13) * (35 % -2)* 15/3)

a. 10.0 b. -10.0 c. 15.0 d. -15.0

18.str="R and Data Science"

z=str.split()

newstr="=".join([z[2].upper(),z[3],z[2]+z[3],z[1].capitalize()])

newstr is equal to ____________________________

19.Given the following dictionary

colors = {"Red":111, "Blue":333, "Green":555}

Which statement will delete the element “Blue”:333 ?


a. clear colors(“Blue”) b. clear colors(“Blue”:111)

c. del colors(“Blue”) d. del colors[“Blue”]

20.Which of the following can be used to read the next line from a file object fobj?

(a)fobj.read(2) (b)fobj.readline() (c)fobj.read() (d)fobj.readline(2)

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( ):

___________ # Missing statement

a=500

show( )

invoke( )

print(a)

22.The <filehandle>.seek( 8 ) if applied to a text file stream object moves the read cursor /

pointer :

a) 8 characters backwards from its current position

b) 8 characters backward from the end of the file

c) 8 characters forward from its current position

d) 8 characters forwarded from the beginning of the file

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())

24.Fill in the Blank

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

26.What will the following code do?

dict={"Exam":"AISSCE", "Year":2022}

dict.update({"Year”:2023} )

a. It will create new dictionary dict={” Year”:2023}and old dictionary

will be deleted

b. It will throw an error and dictionary cannot updated

c. It will make the content of dictionary as dict={"Exam":"AISSCE", "Year":2023}

d.It will throw an error and dictionary and do nothing

27.What will be the value of the expression :14+13%15

28.Select the correct output of the code:

a= "Year 2022 at All the best" a = a.split('2')

a = a[0] + ". " + a[1] + ". " + a[3] print (b)

(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?

S="Welcome to class XII" # Statement 1print(S) # Statement 2 S="Thank you" #


Statement 3
S[0]= '@' # Statement 4

S=S+"Thank you" # Statement 5

a. Statement 3 (b) Statement 4

b. Statement 5 (d) Statement 4 and 5

31.The correct syntax of seek() is:

(a) file_object.seek(offset [, reference_point]) (b) seek(offset [, reference_point])

(c) seek(offset, file_object) (d)

seek.file_object(offset)

State True or False:

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:

crick="IPL 2024 final"

print(crick[-1:4:-2])

a)InF4 b)IN40 c) lnf40 d) INF0

34.Suppose a tuple K is declared as K = (100, 102, 143, 309), which of the


following is incorrect?

a)print(K[-1]) b) K[3] =405 c) print(min(K)) d) print(max(K))

35.What impossible output(s) will be obtained when the following code is


executed?

import random

STRING="GOD LIKES ALL "

NUMBER=random.randint(0,3)

N=5

while STRING[N]!="L":

print (STRING[N] +STRING[NUMBER] + "#",end="")

NUMBER=NUMBER+1

N=N-1

a) I# b) IG# c) IO# d) ID#

36.Give the output

def fun(a):

a=10

print(a)

a=5

fun(a)

print(a)

a) 10,10 b) 5,10 c) 10,5 d) error

37.State whether the following statement is True or False:

Python throws errors and exceptions when the code goes wrong, which may cause the
program to stop abruptly.

38. StateTrueor False


“Thecharactersofstringwillhavetwo-wayindexing.”
39. Whichofthefollowingisthevalidvariablename?
(a)f%2 (b) 20ans (c)ans (d)$ans

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

45. Atextfilestudent.txtis storedinthestoragedevice.Identify the correctoption


outofthefollowingoptionstoopenthefileinreadmode.
i. myfile=open('student.txt','rb')

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

46.State True or False:


AtryblockinPythonmustalwaysbefollowedbyanexceptblock.

What will the following expression be evaluated to in Python?


print(6*3 / 4**2//5-8)
(a) -10 (b)8.0 (c)10.0 (d) -8.0

47.The __________ statement is an empty statement in Python.

48.Which of the following is not a keyword?

(a) eval (b) assert (c) nonlocal (d) pass

49.What will be the output for the following Python statements?

D= {“Amit”:90, “Reshma”:96, “Suhail”:92, “John”:95}

print(“John” in D, 90 in D, sep= “#”)

(a) True#False (b)True#True (c) False#True (d)


False#False

50.What will the following Python statement evaluate to?

print (5 + 3 ** 2 / 2)

(a) 32 (b) 8.0 (c) 9.5 (d) 32.0

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

does not exist?

(a) r+ (b) w+ (c) a+ (d)


Both (b) and (c)

53.Identify the errors in the following code:

MyTuple1=(1, 2, 3) #Statement1

MyTuple2=(4) #Statement2

MyTuple1.append(4) #Statement3

print(MyTuple1, MyTuple2) #Statement4

(a) Statement 1 (b) Statement 2

(c) Statement 3 (d) Statement 2 &3

54.The correct statement to place the file handle fp1 to the 10th byte from the
current

position is:

(a) fp1.seek(10) (b) fp1.seek(10, 0)

(c) fp1.seek(10, 1) (d) fp1.seek(10, 2)

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]

56.State whether True or False:

Variable names can begin with the _ symbol.


1. Identify which of the following is an invalid data type in Python:

(a) int (b) float (c) super (d) None

57.Consider the following code

dict1 = {‘Mohan’: 95, ‘Ram’: 89, ‘Suhel’: 92, ‘Saritha’: 85}

58.What suitable code should be written to return a list of values in dict1

Consider the following expression:

not True and False or not False

Which of the following will be the output:

a) True b) False c) None d) NULL

59.Select the correct output of the following code:

>>>str1 = ‘India is a Great Country’

>>>str1.split(‘a’)

a) [‘India’,’is’,’a’,’Great’,’Country’]

b) [‘India’, ’is’, ’Great’, ’Country’]

c) [‘Indi’, ’is’, ’Gre’, ’t Country’]

d) [‘Indi’, ’is’, ’Gre’, ’t’, ‘Country’]

60.Which of the following is an invalid access mode for text files:

a) w b) a+ c) ab d) r

61.Fill in the blanks:

______ command is used to add a new column in the table in SQL

62.Which of the following will be the output of the code:

mySubject = “Computer Science”

print(mySubject[:3] + mySubject[3:])
a) Com b) puter Science

c) Computer Science d) Science Computer

63.The correct syntax of load( ) is:

a) <objectvariable> = pickle.load(<fileobject>)

b) pickle.load(<fileobject>, <objectvariable>)

c) <fileobject>.load(<objectvariable>)

d) <objectvariable> = <fileobject>.load( )

64.How will the following expression be evaluated in Python?

2 + 9 * ( ( 3 * 12) – 8 ) / 10

a) 29.2 b) 25.2 c) 27.2


d) 27

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

(c) A is True but R is False

(d) A is False but R is True

65.State True or False :

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?

a) varchar2(50) b) number c) number(5,2) d) number(6)

67.What will the following expression be evaluated to in Python?

print( ( - 33 // 13) * (35 % -2)* 15/3)


str="R and Data Science"

z=str.split()

newstr="=".join([z[2].upper(),z[3],z[2]+z[3],z[1].capitalize()])

newstr is equal to ____________________________

Given the following dictionaries:

dict_fruit={"Kiwi":"Brown", "Cherry":"Red"}

dict_vegetable={"Tomato":"Red", "Brinjal":"Purple"}

68.Which statement will merge the contents of both dictionaries?

a) dict_fruit.update(dict_vegetable) b) dict_fruit + dict_vegetable

c) dict_fruit.add(dict_vegetable) d) dict_fruit.merge(dict_vegetable)

69.Which output line(s) of the following program will print the


same results? tup1 = (10, 20, 30, 40, 50, 60, 70, 80, 90)

print(tup1[5:-1]) # Statement 1

print(tup1[5]) # Statement 2

print(tup1[5:]) # Statement 3

print(tup1[-4:8]) # Statement 4

70.Consider the Python statement, t=(10,20,30,40,50,60) Identify from the


options below that will result in an error

a) t[4]+44 b) t[4]-44 c) t=t-(70,) d) t=t+(70,)

71.What possible output(s) are expected to be displayed on screen at the time of


execution of the program from the following code? Select correct options (can
also choose more than one option) from below.

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="@")

a) 30 $@40 $@50 $@70 $@90

b)30 $@40 $@50 $@70 $@90 $@

c) 30 $@40 $@70 $@90 $@

d) 40 $@50 $@

72.Complete the missing line of code in #statement 1 to produce


the output as 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())

Consider the code:

lines = ['This is line 1', 'This is line 2']

with open('readme.txt', 'w') as f:

for line in lines:

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

74.Whichof the following is an invalid datatypein


Python?

(a) list(b) Dictionary (c)Tuple (d)Class

75.Giventhe following dictionaries


dict_fruit=("Kiwi":"Brown", "Cherry":"Red")
dict_vegetable=("Tomato":"Red", "Brinjal":"Purple"}
Which statement will merge the contents of both
dictionaries?

(a)
dict_fruit.update(dict_vegetable)

(c) dict_fruit.add(dict_vegetable)

(b) dictfruit + dict_vegetable

(d) dict_fruit.mere(dict_vegetable)

76.Considerthe given
expression:

notFalse and False or


True

77.Whichof the following will be correct output if the given expression


isevaluated?

a.Trueb. False c. NULL .d.NONE


78.Selectthe correct output of
the code:

count= 0

while (True):

ifcount % 3 == 0:

print(count, end = " ")

if(count >15):

break;

count+= 1

(a) 012..... 15 (b) Infinite loop (c) 03 69 12 15 (d) 0


369 12

79.Whichof the following is not a valid


mode to open a file?

(a) A (b) ab (c) r+ (d) w

80.Whatpossible output(s) are expected to be displayed on screen at the time


ofexecutionof the program from the following code?

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

81.Whatwill the following expression be evaluated to in


Python?

print(16-(3+2)*5+2**3*4)

(a) 54

(b) 46

(c) 23

(d) 32

82.Whatwill be the output of the following Python


code?

try:

a=10
b=0

print('result=',a/b)

exceptException as
error:

print(error)

else:

print('No error')

(a) 0 (b) No error


(c) valueerror

(d) Division byzero

83.Givenis a Python string


declaration:

message="Bring it
on!!!"

Write the output of:


print(message[::-2])

Write the output of the code given


below:

book_dict= {"title": "You can win",


"copies":15}

book_dict['author'] = "Shiv Khera"


book_dict['genre'] =

"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])

a) sWfr b)frWs c)sWrf d)‘ ’

86.Whichofthe following is
akeywordin Python?

b) True b)len c)pow d)sort

87.Giventhefollowingdictionaries:
dict_student={"rno":"53","name":‘Rajve
erSingh’} dict_marks = {"Accts" : 87,
"English" : 65}

88.Whichstatementwillmergethe contentsofbothdictionaries?

c) dict_student+ dict_marks b)dict_student.add(dict_marks)

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

ME = “Nothing costs more than Truth”


#Statement3 EM*=2 #Statement 4

EM[-1:-3: -1] +=ME[:7] #Statement 5

(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

d) S1 b) S3 c)S4 d)No errorwill begenerated

91.Considerthefollowingexpression:not((TrueandFalse)orTr
ueandFalse) What would it return?

(a)False b)None c) True d)Error

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=’%’)

a) Java%Ruby% b) Ruby%C++% c)Ruby%C++ d)Java%Ruby

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

You might also like