Day2 QP
Day2 QP
No Section-A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from
this section. Choose the best possible option.
1. In which of the following modes the existing data in the file will be lost?
i. w ii. w+ iii. a iv. r+
a) i & iii b) i & iv c) i,ii&iii d) i & ii
2. What is the return type of readlines() method?
a) list b) tuple c) string d) no return type
3. Which statement in Python will move the file pointer 10 bytes backward
from the current position?
a) f.seek(-10,0) b) f.seek(10,0) c) f.seek(-10,1) d) f.seek(-10,2)
4. Which is the correct way to express xy ?
a) pow(x) b) x**y c) x^^y d) x^y
5. Suppose d={“Riddhi”:40,”Rithvik”:45}, what will happen if we try to
retrieve a
value using the expression d[“Riya”]
a) Since “Riya” is not a value in the dictionary, Python raises a KeyError
exception
b) No error and return None
c) Since “Riya” is not a key in the dictionary, Python raises a KeyError
exception.
d) Since “Riya” is not a key in the dictionary, Python raises a Syntax error.
6. Which of the following option can be used to read the whole content of a
text file Myfile.txt?
a) myfile =open(“Myfile.txt”) b) myfile=open(“Myfile.txt”,’r’)
myfile.readlines(5) myfile.read(n)
c) myfile=open(“Myfile.txt”) d) myfile=open(“Myfile.txt”)
myfile.readline() myfile.read()
2
7. Which of the following statement in Python is used to open a text file
“REMARKS.TXT” and read the existing contents from it.
a) file=open(“REMARKS.TXT”,”w”) b) file=open(“REMARKS.TXT”,a)
c) file=open(“REMARKS.TXT”,”r”) d) file=open(“REMARKS.TXT”,w+)
8. Identify the data type which stores the values as key-value pairs?
a) Dictionary b) List c) String d) Tuple
9. Which of the following operator has the highest precedence?
a) ** b) | c) % d) >>
10. Which of the following function call can be used to invoke the below
function definition?
def calc(p,q,r,s)
i) calc(3,4,5,6) ii) calc(p=1,2,3,5) iii) calc(3,4,r=3,s=5)
iv)calc(q=4,p=3,s=5,r=7)
a) i,ii,iii,iv are correct b) i, iii, iv are correct
c) i, ii, iii are correct d) i and iv are correct
11. The syntax of pickle.dump() method is____________.
a) pickle.dump[data_object,file_object] b) pickle.dump[file_object,data_object]
c) pickle.dump(data_object,file_object) d) pickle.dump(data_object)
12. Given the list L=[1,3,[6,5,7],82,11,92,[5,6,7]]. What will be the output of
L[1:-2:2]?
a) [3,[6,5,7],82,11,92] b) 3,82 c) [3, 82] d) [3,82,92]
13. How many arguments are passed to tell() method?
a) 0 b) 1 c) 2 d) 3
14. Which of the following statement is true?
a) A binary file takes much time to process
b) A text file consists of human readable characters.
c) A binary file contains a delimiter.
d) A text file can be processed faster than binary file.
3
15. Which one of the following is incorrect?
a) The variables used in a function are called local variables.
b) The local variables of a particular function can be used inside other
functions but cannot be used in global space.
c) The variables used outside a function are called global variables.
d) In order to change the value of a global variable inside function, keyword
global is used.
16. Consider a tuple Y=(10,20,30,40,50). Which of the following statement can
be used with tuple?
a) Y[0]+=2 b) Y+=2 c) Y*=2 d) Y[2]=80
17. If return statement is not used inside a function, the function will return
a) 0 b) Null c) None d) Arbitary value
18. Identify the statement in Python which reads the entire content of the CSV
file as a nested list from a file object “FILE1”.
a) FILE1.read() b) FILE1.reader()
c) csv.reader(FILE1) d) FILE1.readlines()
19. Identify the datatype of (3,)
a) Tuple b) List c) Integer d) String
20. CITY.CSV contains the following details
Chennai,Mylapore
Mumbai,Andheri
Read the following program and give the output.
import csv
d=csv.reader((open(“c:\PYPRG\ch13\CITY.CSV”)))
next(d)
for row in d:
print(row)
4
a) [‘Chennai’,’Mylapore’] b) [‘Mumbai’,’Andheri’]
c) Chennai d) Chennai,Mylapore
Mumbai Mumbai,Andheri
21. Identify the file mode that is not valid to open CSV file?
a) a b) w c) ab d) r
22. Which of the following is not an individual unit in a Python program?
a) Keywords b) Identifiers c) Literals d) Function
23. CSV files can take only comma as the delimiter. (True/False)
a) True b) False c) Machine dependent d) No delimiter
24. How do you read and display the datas from a binary file “mybinary.dat”?
a) fileobject=open(“mybinary.dat”,”rb”)
b) fileobject=open(“mybinary.dat”,rb”)
objectvar=pickle.load(fileobject)
c) import pickle
fileobject=open(“mybinary.dat”,rb”)
objectvar=pickle.load(fileobject)
fileobject.close()
d) import pickle
fileobject=open(“mybinary.dat”,rb”)
objectvar=pickle.load(fileobject)
fileobject.close()
print(objectvar)
25. Assume that the position of the file pointer is at the beginning of 6th line in
a text file. Which of the following options can be used to read all the
remaining lines?
a) myfile.read(n-6) b) myfile.read(n)
c) myfile.readline() d) myfile.readlines()
SECTION B
This section consists of 24 Questions (26 to 49) . Attempt any 20 questions.
26. Identify the output of the following statements.
p=4
5
q=2
for i in range(1,p+2):
q=p+(q*i)
print(q)
a) 1540 b) 1604 c) 1450 d) 1064
27. Suppose the content of the “Poem.txt” is
The blossom will always grow.
The seasons will always change.
People come and go.
Their shadows comforting and strange.
What will be the output of the following code?
Myfile=open(“E:\poem.txt”,”r”)
str=Myfile.readline()
print(str,end=” “)
str=Myfile.readline()
print(str,end=””)
str=Myfile.readline(5)
print(str,end=””)
Myfile.close()
a) The blossom will always grow. b) The blossom will always grow.
The seasons will always change. The seasons will always change.
People Peopl
c) The blossom will always grow. d) The blossom will always grow.
The seasons will always change. The seasons will always change.
People come and go. People come and go.
Their shadows comforting and strange.
28. Identify the output of the following statements.
R=[[“a”,”b”,”c”],[“d”,”e”,”f”],[“g”,”h”,”i”]]
6
print R[1:][1]
a) [‘a’,’b’,’c’] b) ‘e’ c) [‘e’],[’h’] d)[‘g’,’h’,’i’]
29. Consider the following directory structure.
What will be the absolute path of Infrastructure?
a) Final\Infrastructure b) D:\Data\Final\Infrastructure
c) ..\Final\Infrastructure d)..\Shapefiles\Final\Infrastructure
30. What is the output of the following code?
A tuple T is declared with the following values.
B=(‘a’,’b’,’I’,’II’,[1,2,3],[“Name”,”Class”,”Subject”,”Section”],10,20)
What will be the output of
T=B[-6:-3]+B[-4:-2]
print(B)
a) ('a','b','I','II',[1,2,3],["Name","Class","Subject","Section"],10,20)
b) ('I','II',[1,2,3])
c) ('II',[1,2,3],["Name","Class","Subject","Section"],10,20)
d) ('I','II',[1,2,3],[1,2,3],["Name","Class","Subject","Section"])
31. Predict the output of the following Python code.
List1=[3,2,5,7,3,6]
List1.remove(3)
print(sum(List1)
a) 23 b) 20 c) 19 d) 17
7
32. Ms. Radhika is working on the Books.dat file but she is confused about how to
read data from the binary file. Suggest a suitable line in statement1 for her to
fulfill her wish.
a) load() b) data=pickle.load(f1)
c) data=f1.load() d) f1.load(data)
33. Suppose content of 'msg.txt' is
Satyameva Jayathe
What will be the output of the following code?
f1 = open("msg.txt",'r')
t = list("yethi")
c=0
n = f1.read()
for i in n:
if(i in t):
c+=1
print(c)
f1.close()
a) 6 b) 5 c) 7 d) 4
34. def a(b):
b=b+[5]
c=[1,2,3,4]
a(c)
print(len(c))
a) 4 b) 5 c) 1 d) Exception is thrown
8
35. Consider the following text file “Details.txt”
I am a student of class 12.
I like Computer Science.
I am good at programming.
What will be the output of the following code?
F1=open(“Details.txt”,”r”)
T=F1.read()
R=T.split()
C=0
for i in R:
if len(i)<=3:
c+=1
print(c)
F1.close()
a) 3 b) 4 c) 5 d) 9
36. Predict the output of the following Python code.
def Change(P,Q=30):
P=P+Q
Q=P-Q
print(P,’#’,Q)
return(P)
R=150
S=100
R=Change(R,S)
print(R,’#’,S)
S=Change(S)
9
a) 250#100 b) 200#100 c) 250 # 150 d) 150#100
200#100 150#100 250 # 100 250#50
130#50 50#100 130 # 100 150#100
37. Give the output of the following Python code.
a = 15
def update(x):
global a
a += 2
if x%2==0:
a *= x
else:
a //= x
a=a+5
print(a, end="$")
update(5)
print(a)
a) 20$11 b) 15$4 c) 20$4 d) 22$4
38. Which of the following will give same output for tup1=(1,2,3,4)
i) print(tup1[:-1]) ii) print(tup1[0:5])
iii) print(tup1[0:4])iv) print(tup1[-4:])
a) i,ii b) ii,iv c) i,iv d) ii,iii,iv
39. Give the output of the following program.
L=list(“www.csiplearninghub.com”)
print(L[20 : 0])
a) Error b) No value c) None d) []
10
40. Give the output of the following program.
f=open("test.txt","w+")
f.write("File\nHandling")
f.seek(0)
a=f.readline(2)
print(a)
a) File\nHandling b) FileHandling c) Fi d) No output
41 def convert(old):
L=len(old)
new=””
for I in range(0,L):
if old[I].isupper():
new=new+old[I].lower()
elif old[I].islower():
new=new+old[I].upper()
elif old[I].isdigit():
new=new+”*”
else:
new=new+”%”
return new
Older=”PaNDeMIC@2021”
Newer=convert(Older)
print(Newer)
a) pAndEmic%**** b) pAndEmic%***
c) pAndEmic**** d) PAndEmic%****
42. Evaluate the following expression.
6 * 3 + 4**2 // 5 – 8
a) 11 b) 13 c) -3 d) 12
11
43. Consider the text file given and give the output of the following code.
I am a student of class 12.
I like Computer Science.
I am good at programming.
F1=open(“Details.txt”,”r”)
P=F1.read()
W=P.count(‘am’)
print(W)
F1.close()
a) 2 b) 3 c) 4 d) 0
44. Give the output of the following program.
def sample(a=1,b=1):
global x,y
x=a+b
a,y=a+x,a*x
print(a,b,x,y)
sample(2,3)
print(sample())
a) 7 3 5 10 b) 7 3 5 10
3122 3122
None
c) 9 3 5 12 d) 9 3 5 12
25 5 15 150 25 5 15 150
None
45. Consider the following Python code and fill in the blank with appropriate
statement to get the output as 21.
var = 10
for i in range(10):
12
for j in range(2, 10, 1):
if var % 2 == 0:
_________________ # Statement 1
var += 1
var+=1
else:
var+=1
print(var)
a) break b) repeat c) continue d) return
46. Consider the text file “smile.txt” and write the output of the code given
below.
Smile more and frown less,
Can help us when we feel stressed
Smile more and frown less,
Is better than putting on a pretty dress.
file=open(“smile.txt”)
contents=file.read()
c=0
for I in contents:
if I in “Ss”:
c+=1
print(c)
a) 12 b) 13 c) 14 d) 15
47. Which of the following Python code will give different output from the others?
a) for i in range(0,5): b) for j in [0,1,2,3,4]:
print(i) print(j)
c) for k in [0,1,2,3,4,5]: d) for I in range(0,5,1):
print(k) print(I)
13
48. Assume the content of the file “Myfile.txt” is
Extreme
Good
Happy
Today
What will be the data type of rec in the following code?
file=open(“Myfile.txt”)
rec=file.readline()
file.close()
a) string b) list c) tuple d) dictionary
49. Which is NOT the possible output for the following Python code?
import random
flowers=[“Rose”,”Jasmine”,”Sunflower”,”Lily”]
for I in range(random.randint(0,2)):
print(flowers[I],’*’,end=” “)
a) Rose* Jasmine* b) Rose* Jasmine* Sunflower*
c) Rose* d) No output
SECTION C
CASE STUDY BASED QUESTIONS
This section consists of 6 Questions (50 -55) Attempt any 5 questions.
Ashvik of class 12 has written a program to add more 10 records in an existing
file “datas.csv” which contains student id, student name, class and marks. But
he is not able to complete the program. Help him to complete the task
successfully.
Incomplete code
_________________ # Statement 1
F1=open(_________________, _____________, newline=’’) #Statement 2
stud=csv._______________ #Statement 3
14
details=[]
for i in range(10):
studentid=int(input(“Enter Student Id”))
studname=input(“Enter student name”)
studclass=input(“Enter class”)
studmark=float(input(“Enter marks”))
record=[___________] #Statement 4
details.append(_______) # Statement 5
stud.___________________(details) #Statement 6
F1.close()
50. Identify the suitable code in statement 4.
a) “studentid”,”studname”,”studclass”,”studmark”
b) studentid,studname,studclass,studmark
c) STUDENTID,STUDNAME,STUDCLASS,STUDMARK
d) studentid,studname,Studclass,Studmark
51. Identify the missing code for blank space in line marked as Statement 2.
a) “datas.csv”,”wb” b) “datas.csv”,”a” c) “datas.csv”,”w” d) “datas.cvs”,”a”
52. Choose the function name that should be used in the blank space of the line
marked as statement 6 to create the desired file.
a) dump() b) load() c) writerows() d) writerow()
53. Identify the suitable code for blank space in the line marked as
Statement 1.
a) load CSV b) read csv c) import csv d) import CSV
54. Identify the suitable code for blank space in statement 5.
a) stud b) record c) details d) insert
55. Choose the function name (with argument) that should be used in blank space of
statement 3.
a) writer(F1) b) reader(F1) c) read(F1) d) write(F1)
15