Five QN Paper With Answer in Word
Five QN Paper With Answer in Word
Five QN Paper With Answer in Word
Computer Science
Including Projects (Binary files and CSV files)
[Subject Code : 083]
For CLASS
12
Term-I
EXAMINATION
By
Gurmeet Singh
MCA, MSC (IT)
⚫ As per the latest Reduced & bifurcated Syllabus for Term I Examination to be held in
November-December 2021.
⚫ Chapterwise Multiple Choice Questions.
⚫ The latest CBSE Sample Question Paper for Term I Examination to be held in November-December 2021.
⚫ 5 Model Test Papers based on the latest CBSE Sample Question Paper for Term I Examination.
Disclaimer
• All the brand, product names and logo referred to in this book are hereby acknowledged to be the trademarks of
their respective organisations. We are not associated with any product or vendor mentioned in this book.
• Due care and diligence has been taken while writing, editing and printing the book. Neither the
author nor the publishers of the book hold any responsibility for any mistakes that may have inadvertently crept in.
We are pleased to present our book SCORE PLUS Question Bank and CBSE Sample Paper with
Model Test Papers in Computer Science for Class XII (Subject Code 083) in strict accordance
with the Latest Reduced of bifurcated Syllabus and the Latest Sample Question Paper released
by the Central Board of Secondary Education, New Delhi, for Term I Examination to be held in
November-December 2021.
This book contains the brief introduction of each topic with solved examples. In each chapter,
topicwise questions have been set. “Easy to difficult” level of questions is maintained. We have
tried to clear all the concepts in easy language and with solved examples. Most of the questions
are taken from the last year CBSE paper or based on CBSE pattern.
In the next part of book, sample question paper of Computer Science released by CBSE with
its solution is published. After sample paper, there are 5 model test papers with their solutions
prepared keeping in mind the blueprint of the CBSE sample question paper.
Some specific features of this book are:
⚫ Strictly as per the latest Reduced and bifurcated syllabus and the latest CBSE Sample
Question Paper released by the CBSE for Term I Examination to be held in November
December 2021.
⚫ Chapterwise Question Bank provides topicwise comprehensive range of solved and
unsolved questions including questions from past years’ papers to provide thorough
understanding of the chapter.
⚫ The latest CBSE Sample Question Paper for Term I Examination to be held in November-
December 2021.
⚫ 5 Model Test Papers based on the latest CBSE Sample Question Paper for Term I
Examination.
We hope this book provides enough practice materials and would help students in scoring high
during this academic year along with the final board examination.
Author
Syllabus
COMPUTER SCIENCE
CLASS-XII Code No. 083
2021-22
1. Prerequisites
Computer Science- Class XI
2. Learning Outcomes
Student should be able to
(a) apply the concept of function.
(b) explain and use the concept of file handling.
(c) use basic data structure: Stacks.
(d) explain basics of computer networks.
(e) use Database concepts, SQL along with connectivity between Python and SQL.
3. Distribution of Marks:
Total 35 35
4. Unit wise Syllabus
TERM I
Unit I: Computational Thinking and Programming – 2
• Revision of Python topics covered in Class XI.
• Functions: types of function (built-in functions, functions defined in module, user defined functions),
creating user defined function, arguments and parameters, default parameters, positional parameters, function
returning value(s), flow of execution, scope of a variable (global scope, local scope)
• Introduction to files, types of files (Text file, Binary file, CSV file), relative and absolute paths
• Text file: opening a text file, text file open modes (r, r+, w, w+, a, a+), closing a text file, opening a file using
with clause, writing/appending data to a text file using write() and writelines(), reading from a text file using
read(), readline() and readlines(), seek and tell methods, manipulation of data in a text file
• Binary file: basic operations on a binary file: open using file open modes (rb, rb+, wb, wb+, ab, ab+), close a binary
file, import pickle module, dump() and load() method, read, write/create, search, append and update operations
in a binary file
• CSV file: import csv module, open / close csv file, write into a csv file using csv.writerow() and read from a csv
file using csv.reader( )
SECTION - A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Find the invalid identifier from the following:
(a) Total*Tax (b) While (c) Column31 (d) switch
2. Consider a declaration L = {“1”:(1,2,3)}
Which of the following represents the data type of L?
(a) list (b) tuple (c) dictionary (d) string
3. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (t [3::2])?
(a) (40,60,80) (b) (30,50,70) (c) (30,050,70,90) (d) (40,60)
4. Which of the following options is correct?
(a) if file is opened in r mode, file is opened for reading only
(b) if file is opened in r mode, file is opened for reading and writing both
(c) if file is opened in r mode, file is opened for writing only
(d) if file is opened in r mode, file is opened for reading and appending
5. Which of the following options can be used to read complete text file as String?
(a) myfile = open(‘Myfile.txt’); myfile.read() (b) myfile = open(‘Myfile.txt’,’r’); myfile.read(n)
(c) myfile = open(‘Myfile.txt’); myfile.readline() (d) myfile = open(‘Myfile.txt’); myfile.readlines()
6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following
option can be used to read the 3rd line?
(a) myfile.read() (b) myfile.readline(3) (c) myfile.readline() (d) myfile.readlines()
7. Identify the correct option out of the following options to open the binary file in write mode.
(a) myfile = open(‘student’,’wb’) (b) myfile = open(‘student’,’w+b’)
(c) myfile = open(‘student’,’bw’) (d) all of the above
8. Choose the correct function name required to check if a string contains only uppercase letters.
(a) isupper() (b) upper() (c) toupper() (d) onlyupper()
9. Which of the following is not valid?
(a) “5”*3 (b) “5” in [“1”,”2”,”5”] (c) ”5”+”5” (d) ”5”/”5”
10. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
(a) print(T[1]) (b) T.append(5) (c) max(T) (d) len(T)
132 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
11. Which of the following statements is correct in the context of binary files?
(a) A binary file stores the data in the same way as stored in the memory.
(b) We can read a binary file using a text editor.
(c) Every line ends with a new line character.
(d) A binary file stores data in their ASCII values and are in a human readable format.
12. What is the significance of the tell() method?
(a) tell the length of file
(b) tell the current position of the file pointer
(c) tell the type of file
(d) tell the end position within file
13. Which of the following statements is correct to store list L in binary file object f.p is the object of pickle library?
(a) p.dump(L,f) (b) L.dump(p,f) (c) f.dump(L,p) (d) p.dump(f,L)
14. Minimum argument required in seek function is
(a) 0 (b) 1 (c) 2 (d) 3
15. Function blocks begin with the .
(a) fun (b) define (c) def (d) open
16. Which of the following function header is incorrect?
(a) def sum(a,b,c); (b) def sum(a,b,c=10); (c) def sum(a,b=5,c=10); (d) def sum(a=4,b,c=10);
17. Which of the following is the correct way to call a function?
(a) func() (b) def func() (c) call func (d) call func()
18. Which of the following characters acts as default delimiter in a csv file?
(a) (hash) # (b) (dot) . (c) (comma) , (d) (vertical line) |
19. Choose the correct option for reading csv file.
(a) data=csv.reader(f) (b) data=csv[reader.f] (c) data=csv.reader[f] (d) data=csv(reader.f)
20. Which method returns the current row and moves to the next row in csv file?
(a) move() (b) next() (c) cur() (d) currow()
21. Which of the following options is incorrect?
(a) Reading and Writing both can be done when file is opened in r+ mode.
(b) When file is opened in r+ mode the file pointer is placed at the beginning of the file.
(c) Only Reading in binary file can be done when file is opened in rb+ mode.
(d) When file is opened in rb+ mode the file pointer is placed at the beginning of the file.
22. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print(t[-2:])?
(a) (80, 90) (b) (80) (c) no output (d) (90, 80)
23. Choose the correct name of the immutable data object from the following:
(a) List (b) Set (c) String (d) Dictionary
24. The file pointer is placed at the beginning of the file when the file is opened in
(a) r (b) r+ (c) rb (d) all of the above
25. Which of the following is false about a dictionary?
(a) Keys and values are unique within a dictionary
(b) The values of a dictionary can be of any type.
(c) The keys must be of an immutable data type such as strings, numbers, or tuples.
(d) Each key-value pair maps the key to its associated value.
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 133
SECTION - B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. What is the output of following code:
a=20
b=30
a,b=b+20,a+30
print(a,b)
(a) 50,50 (b) 50,80 (c) 70 50 (d) 70 80
27 Suppose content of ‘Myfile.txt’ is:
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
f = open(“Myfile.txt”)
data=f.readline()
data=f.readline()
print(data)
f.close()
(a) Twinkle twinkle little star (b) How I wonder what you are
(c) Twinkle twinkle little star (d) Twinkle twinkle little star
How I wonder what you are How I wonder what you are
Up above the world so high
Like a diamond in the sky
28. Identify the output
t=(3,2,1)
print(t*3)
(a) (9,6,3) (b) (3,2,1,3,2,1,3,2,1) (c) (3,3,3,2,2,2,1,1,1) (d) (3,2,1),(3,2,1),(3,2,1)
29. How many times will the following loop execute and give the output?
z=7
sum=0;
while z<=12:
sum=sum+z
z=z+2
print(z)
(a) 3 times, output-13 (b) 3 times,output-12 (c) 4 times,output-11 (d) 4 times,output-12
30. What will be displayed after the execution of the following loop?
Total,End=5,15;
for Turn in range(1,End,2):
Total+=1
print(Total,Turn)
(a) 11,12 (b) 13,13 (c) 11,15 (d) 12,13
31. Select the correct output
L=[1,2,3,4,5,3]
L.pop(3)
print(L)
(a) [1,2,4,5] (b) [1,2,3,5,3] (c) [1,2,4,5,3] (d) [1,2,3,4,5]
134 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
32. Rahul is trying to write a Dictionary Dic={1:’Aman’,2:’Karan’,3:’Diya’} on a binary file test.bin.
Consider the following code written by him.
import pickle as p
Dic={1:’Aman’,2:’Karan’,3:’Diya’}
with open(‘test’,’wb’) as f:
#statement 1
Identify the missing code in Statement 1.
(a) p=dump(f) (b) p.dump(Dic,f) (c) p,dump(f,Dic) (d) f.dump(Dic,p)
33. A binary file employee.dat has following data
Empno empname Salary
101 Anuj 50000
102 Arijita 40000
103 Hanika 30000
104 Firoz 60000
105 Vijaylakshmi 40000
def display(eno):
f=open(“employee.dat”,”rb”)
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
#Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is 90000.
Write appropriate jump statement from the following to obtain the above output.
(a) jump (b) break (c) continue (d) return
34. What will be the output of the following Python code?
def sum(a,b=10):
print(a+b)
sum(15,25)
sum(15)
(a) 40 (b) 25 (c) 35 (d) 40
25 25 15 10
35. Evaluate the following expression and identify the correct answer.
x = 6 + 36/6 + 2*5
(a) 45.0 (b) 17.0 (c) 26.25 (d) 22.0
36. Observe the following code carefully and find which statement will never get executed in the code.
counter=1 #statement1
while counter<=15: #statement2
if counter<15: #statement3
print(“Jump”) #statement4
else: #statement5
print(“Stop”) #statement6
counter+=4 #statement7
(a) statement2 (b) statement4 (c) statement6 (d) statement7
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 135
37. What will be the output of the following code?
def fun():
a=10
print(a,end=”#”)
a=5
fun()
print(a)
(a) 10#5 (b) 10#10 (c) 5#5 (d) 5#10
38. What are the possible outcome(s) executed from the following code?
import random
STRING=”CBSEONLINE”
NUMBER=random.randint(0,3)
N=9
while STRING[N]!=”L”:
print (STRING[N] +STRING[NUMBER] + “#”,end=””)
NUMBER=NUMBER+1
N=N-1
(i) ES#NE#IO# (ii) LE#NO#ON# (iii) NS#IE#LO# (iv) EC#NB#IS#
(a) (i) and (ii) (b) (ii) and (iii) (c) (i) and (iv) (d) (iii) and (iv)
39. What output will be generated when the following Python code is executed?
def ChangeList():
L=[ ]
L1=[ ]
L2=[ ]
for i in range(1,10):
L.append(i)
for i in range(10,1,-2):
L1.append(i)
for i in range(len(L1)):
L2.append(L1[i]+L[i])
L2.append(len(L)-len(L1))
print (L2)
ChangeList()
(a) [11, 10, 9, 8, 7, 4] (b) [4,7,8,9,10,11] (c) [2,4,6,8,10,11] (d) [10,8,6,4,2,11]
40. Suppose content of ‘Myfile.txt’ is
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king’s horses and all the king’s men
Couldn’t put Humpty together again
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.readline().split()
print(len(record))
myfile.close()
(a) 4 (b) 5 (c) 6 (d) 7
136 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
41. Find the output
def Findoutput():
L=”earn”
x=” “
count=1
for i in L:
if i in[‘a’,’e’,’i’,’o’,’u’]:
x=x+i.swapcase()
else:
if count%2!=0:
x=x+str(len(L[:count]))
else:
count =count +1
print (x)
Findoutput()
(a) EARN (b) EA12 (c) EAR1 (d) EA11
42. Suppose content of ‘Myfile.txt’ is
Honesty is the best policy.
Be Honest.
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.read()
print(len(x))
myfile.close()
(a) 35 (b) 36 (c) 37 (d) 38
43. Which of the following options can be used to read the 2nd line of a text file?
(a) file=f.readlines() (b) file=f.readline()
print(file[1]) print(file[1])
(c) file=f.read() (d) file=f.readlines()
print(file[1]) print(file[2])
44. Observe the following program and answer the questions that follow:
import random
X=3
N=random.randint(1,X)
for i in range(N):
print (i,”#”,i+1)
Find out, which of output(s) out of (a) to (d) will not be expected from the program?
(a) 0#1 (b) 1#2 (c) 2#3 (d) 3#4
45. In f=open(“abc.txt”,”w”), f refers to
(a) file name (b) file object (c) file access mode (d) file pointer
46. When the method display() is executed it reads lines from a text file DIARY.TXT, and display those lines, which
are starting with an alphabet ‘P’.
def display():
file=open(‘DIARY.TXT’,’r’)
l=file.readlines()
for line in l:
if : # statement 1
print (line)
file.close()
Select the appropriate statement to fill the statement 1.
(a) line[1]= =’P’ (b) line[0] =’P’ (c) line(0)= =’P’ (d) line[0]= =’P’
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 137
47. Give the output
f=open(“c:\\abc.txt”)
k=f.seek(10)
g=f.read(5)
t=f.tell()
print(t)
(a) 5 (b) 6 (c) 10 (d) 15
48. Which method is used to read the entire file in the form of string?
(a) read() (b) readline() (c) readlines() (d) all of these
49. What will be the output of the following code?
lt2=[[‘one’,’two’,’three’],[4,5,6]]
print(lt2[0][1],end=”#”)
print(lt2[-1][-1],end=”#”)
print(lt2[0][1])
(a) two#6#two (b) one#6#one (c) two#6#one (d) two#5#two
SECTION - C
Case Study Based Questions.
This section consists of 6 Questions (50-55). Attempt any 5 questions.
Pahul, a student of class 12, is learning CSV File Module in Python. During Final Project he was facing some
problems in code. An incomplete python code (shown below) to create a CSV File ‘Stud.csv’. Help him in
completing the code which creates the desired CSV File.
Fields of CSV File :roll,name
Incomplete Code
import csv
f1= #statement 1
csv_writer=csv.writer(f1,delimiter=’|’,lineterminator=’,’)
ch=’Y’
while ch==’Y’:
r=int(input(‘enter roll :’))
n=input(‘enter name :’)
rec=[r,n]
#statement 2
ch=input(‘more records(Y/N)?’).upper()
print(‘Records are’)
#statement 3
with : #statement 4
csvreader = #statement 5
: #statement 6
print(rows)
50. Identify the suitable code for blank space in the line marked as Statement-1.
(a) f1=open(‘stud.csv’, ‘w’) (b) f1=open(‘stud.csv’, ‘r’)
(c) f1=open(‘stud.csv’, ‘rw’) (d) f1=open(‘stud.csv’)
51. Identify the suitable code for blank space in the line marked as Statement-2.
(a) csv_writer.writerows(rec) (b) csvwriter.writerow(rec)
(c) csv.writer.writerow(rec) (d) csv_writer.writerow(rec)
52. Identify the suitable code for blank space in the line marked as Statement-3.
(a) close(f1) (b) .f1.close() (c) close[f1] (d) f1(close)
138 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
53. Identify the suitable code for blank space in the line marked as Statement-4.
(a) open(‘stud.csv’, ‘rt’) as csvfile (b) .open(‘stud.csv’, ‘rb’) as csvfile
(c) open(‘stud.csv’) as csvfile (d) open(‘stud.csv’, ‘w’) as csvfile
54. Identify the suitable code for blank space in the line marked as Statement-5.
(a) csv.reader(csvfile) (b) csv_reader(csvfile)
(c) csvreader(csvfile) (d) csv.reader(file)
55. Identify the suitable code for blank space in the line marked as Statement-6.
(a) for rows in csv_reader (b) for rows in csv.reader
(c) for rows in csvreader (d) for rows in range [csvreader]
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 139
MODEL TEST PAPER – 2
(Based on the Latest CBSE Sample Paper)
SECTION - A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Find the invalid identifier from the following
(a) 3rdRow (b) Finally (c) Column31 (d) _Total
2. Consider a declaration L = “15”
Which of the following represents the data type of L?
(a) list (b) tuple (c) dictionary (d) string
3. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (t [::2])?
(a) (10, 30) (b) (80, 90) (c) (10, 30, 50, 70, 90) (d) [10, 30, 50, 70, 90]
4. Which of the following options is correct?
(i) if file is opened in r mode, the file pointer is placed at the beginning of the file
(ii) if file is opened in r mode, the file pointer is placed at the end of the file
(iii) if file is opened in r+ mode, the file pointer is placed at the beginning of the file
(iv) if file is opened in r + mode, the file pointer is placed at the end of the file
(a) only (i) (b) (i) and (iii) both (c) (ii) and (iii) both (d) (ii) and (iv)
5. Which of the following options can be used to read all the lines and return them as each line is a string element
in a list?
(a) myfile = open(‘Myfile.txt’); myfile.read() (b) myfile = open(‘Myfile.txt’,’r’); myfile.read(n)
(c) myfile = open(‘Myfile.txt’); myfile.readline() (d) myfile = open(‘Myfile.txt’); myfile.readlines()
6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following
options can be used to read all the remaining lines?
(i) myfile.read() (ii) myfile.read(n)
(iii) myfile.readline() (iv) myfile.readlines()
(a) (i) and (iii) (b) (i) and (iv) (c) (ii) and (iv) (d) (ii) and (iii)
7. Identify the correct option out of the following options to open the text file for reading and writing both.
(i) myfile = open(‘student.txt’,’r+’) (ii) myfile = open(‘student.txt’,’w+’)
(iii) myfile = open(‘student.txt’,’rw’) (iv) myfile = open(‘student.txt’,r+w+)
(a) only (i) (b) both (i) and (iv) (c) both (iii) and (iv) (d) both (i) and (ii)
8. Choose the correct function name required to check the total length of the list.
(a) length() (b) len() (c) size() (d) dimension()
140 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
9. Which is not a valid string?
(a) ‘hello’ (b) “hello” (c) ‘‘‘hello’’’ (d) hello
10. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
(a) sum(T) (b) min(T) (c) max(T) (d) avg(T)
11. Which of the following statements is incorrect in the context of binary files?
(a) A binary file stores the data in the same way as stored in the memory.
(b) We can read a binary file using a text editor.
(c) The .exe files, mp3 file, image files, word documents are some of the examples of binary files.
(d) There is no terminator for a line.
12. method tells the current position of file pointer.
(a) tell() (b) pos() (c) cur() (d) pointer()
13. module is used for serializing and de-serializing a Python object structure.
(a) random (b) math (c) serial (d) pickle
14. In seek(), value sets the reference point at the current file position. (a)
0 (b) 1 (c) 2 (d) 3
15. A function
(a) can’t return any value (b) can return only 1 value
(c) can return 1 or 2 value (d) can return many values
16. Which of the following function header is incorrect?
(a) def greater(a,b) (b) def greater(a=5,b) (c) def greater(a=5,b=10) (d) def greater(a,b=10)
17. Which of the following is the correct way to call a function?
(a) func() (b) func (c) call func (d) call func()
18. Delimiter specifies the character used to separate
(a) each field (b) each word (c) each line (d) each character
19. Which method can be used to read data from csv file?
(a) readdata() (b) read() (c) reader() (d) readcsv()
20. Which function is used to create a writer object in csv file?
(a) csv.writer() (b) csv.write() (c) csv.writedata() (d) csv.writerow()
21. Which of the following options is correct?
(a) Opens a file in w mode for writing only
(b) if we try to open a text file in w mode that exists, overwrites the file
(c) if we try to open a text file in w mode that does not exist, the file gets Created.
(d) All of the above
22. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print(t[:4:])?
(a) (10, 20, 30, 40) (b) (50) (c) (50,60,70,80,90) (d) (10,20,30,40,50)
23. Choose the correct name of the mutable data object from the following:
(a) Int (b) Tuple (c) String (d) Dictionary
24. The file pointer is placed at the beginning of the file when the file is opened in
(a) r mode (b) w mode (c) a mode (d) all of the above
25. Which of the following about a dictionary is false?
(a) Dictionary can be defined by enclosing a comma-separated list of key-value pairs in curly braces ({}).
(b) A colon (:) separates each key from its associated value.
(c) Dictionary is immutable.
(d) The values of a dictionary can be of any type.
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 141
SECTION - B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. Give the output
for i in range(1,10,3):
print(i,sep=”-”,end=”*”)
(a) 1-4-7* (b) 1-4-7-10* (c) 1*4*7* (d) 1*4*7*10
27. Suppose content of ‘Myfile.txt’ is:
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
f = open(“Myfile.txt”)
data=f.readline()
data=f.read()
print(data)
f.close()
(a) Twinkle twinkle little star (b) How I wonder what you are
(c) Twinkle twinkle little star (d) How I wonder what you are
How I wonder what you are Up above the world so high
Up above the world so high Like a diamond in the sky
Like a diamond in the sky
28. L=[10,20,30,40,50]
print(L[2:-2])
(a) [30,40] (b) [30] (c) [20,30,40] (d) [40]
29. How many times does the following while loop get executed?
K=5
L=36
while K<=L:
K+=6
(a) 4 (b) 5 (c) 6. (d) 7
30. What will be displayed after the execution of the following loop?
sum,last=0,10
for C in range(1,last,2):
sum=sum+1;
print(sum,C)
(a) 5,10 (b) 4,9 (c) 5,9 (d) 4,10
31. Choose correct option to sort items in a list lt in descending order.
(a) lt.sort(desc) (b) lt.sort(descending)
(c) lt.sort(reverse=True) (d) it.sort(descending=True)
32. Rahal is trying to read data from a binary file test.bin and store it into List L. Consider the following code
written by him.
import pickle as p
with open(‘test’,’rb’) as f:
#statement 1
Identify the missing code in Statement 1.
(a) f=p.load(L) (b) p=p.load(L) (c) L=p.load(f) (d) f=L.load(p)
142 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
33. The binary file STOCK.DAT is containing following fields
SName and Price
Function Billing() is created in Python to read each record of a pickled file STOCK.DAT, and display the
Total Price of all the records in the file.
import pickle
def Billing():
file=open(‘STOCK.DAT’,’rb’)
IRec=pickle.load(file) #To read the object from file
Totprice=0
for I in IRec:
print (Totprice)
file.close()
Choose appropriate statement to calculate the total price from the following:
(a) Totprice=I[1] (b) Totprice=+I[1] (c) Totprice+=I[1] (d) Totprice=I+Totprice
34. Give the output
print(“hi”)
def abc():
print(“hello”)
print(“bye”)
abc()
(a) hi (b) hi (c) hello (d) bye
hello bye bye hello
bye hello hi hi
35. Evaluate the following expression and identify the correct answer.
c = 25-5*4/2-10+5
(a) 10.0 (b) 35.0 (c) -2.5 (d) -12.5
36. What will be the final value of variable x after the following code is executed:
x=10
while x>1:
x=x//3
x=x+1
print(x)
(a) 0 (b) 1 (c) 2 (d) 3
37. What will be the output of the following code?
def fun():
global a
a=10
print(a,end=”#”)
a=5
fun()
print(a)
(a) 10#5 (b) 10#10 (c) 5#5 (d) 5#10
38. What are the possible outcome(s) executed from the following code?
import random
PLAY=[40,50,10,20]
ROUND=random.randint(2,3)
for J in range(ROUND,1,-1):
print (PLAY[J],”:”,end=””)
(a) 20:10: (b) 20:10:50: (c) 20: (d) 40:50:20:
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 143
39. Find and write the output of the following Python code :
for Name in [“Jayes”, “Ramya”, “Taruna”, “Suraj”]:
print (Name)
if Name[0]== “T”:
break
else:
print (“Finished”)
print (“Got it!”)
(a) Jayes (b) Jayes (c) Jayes (d) Jayes
Ramya Finished Got it! Finished
Taruna Ramya Ramya
Got it! Finished Finished
Taruna
Got it!
40. Suppose content of ‘Myfile.txt’ is
Stay positive and happy
Work hard and don’t give up hope
Be open to criticism and keep learning
Surround yourself with happy, warm and genuine people
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record=myfile.readline()
record = myfile.readline().split()
print(len(record))
myfile.close()
(a) 4 (b) 7 (c) 11 (d) 10
41. Find and write the output of the following Python code :
Str1=”EXAM2018”
Str2=””
I=0
while I<len(Str1):
if Str1[I]>=”A” and Str1[I]<=”M”:
Str2=Str2+Str1[I+1]
elif Str1[I]>=”0” and Str1[I]<=”9”:
Str2=Str2+ (Str1[I-1])
else:
Str2=Str2+”*”
I=I+1
print (Str2)
(a) X*M2M201 (b) E*AMM201 (c) X*MAM201 (d) XXM2M201
42. Suppose content of ‘Myfile.txt’ is
Honesty is the best policy.
Be Honest.
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.read(40)
print(len(x))
myfile.close()
(a) 36 (b) 37 (c) 38 (d) 40
144 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
43. Which of the following options can be used to read the last line of a text file?
(a) file=f.readlines() (b) file=f.readline(-1)
print(file[-1]) print(file)
(c) file=f.read() (d) file=f.read(-1)
print(file[-1]) print(file)
44. Study the following program and select the possible output(s) from the options (a) to (d) following it.
import random
X=random.random()
Y=random.randint(0,4)
print (int(X),”:”,Y+int(X))
(i) 0: 0 (ii) 1:6
(iii) 2:4 (iv) 0:3
(a) (i) and (ii) (b) (ii) and (iii) (c) (iii) and (iv) (d) (i) and (iv)
45. In f=open(“abc.txt”,”w”), ‘w’ refers to
(a) file name (b) file object (c) file access mode (d) file pointer
46. When the function ABLINES() is executed, it read contents from a text file LINES.TXT, to display those lines,
which are either starting with an alphabet ‘A’ or starting with alphabet ‘B’.
def ABLINES():
file=open(‘LINES.TXT’,’r’)
lines = file.readlines()
for w in lines:
if : #statement 1
print (w)
file.close()
Select the appropriate statement to fill the statement 1.
(i) w[0]= =”A” or w[0]= =”B”
(ii) w[0] in [“A”,”B”]
(iii) w[0]= =”A” and w[0]= =”B”
(iv) w[0]= =”A”,”B”
(a) (i) and (ii) (b) (ii) and (iv) (c) (i) and (iv) (d) (ii) and (iii)
47. Give the output
f=open(‘C:\\abc.txt’,’r’)
f.seek(10)
f.seek(5)
k=f.tell()
print(k)
(a) 5 (b) 0 (c) 5 (d) 4
48. EOL stands for
(a) End of Line (b) End of List (c) End of Lists (d) None of these
49. Give the output
lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],[4,5,6]]
lt[2]=lt[3]
lt[0]=lt[1]
lt2[-1][0]=lt[2]+3
print(lt2[1])
(a) [“two”] (b) [4,5,6] (c) [11,5,6] (d) [“two’,”three”]
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 145
SECTION - C
def CSVRead():
try:
with open(‘books.csv’,’r’) as csvf:
cr= #Statement-4
for r in cr:
if : #Statement-5
print(r)
except:
print(‘File Not Found’)
#Statement-6
CSVRead()
You as an expert of Python have to provide the missing statements and other related queries based on the following
code of Amit.
50. Choose the appropriate file name to be opened in append mode (Statement 1).
(a) books.csv (b) books-csv (c) books[csv] (d) books_csv
51. Which statement will be used to create a csv writer object in Statement 2.
(a) csvwriter(csvf) (b) csv.writer(csvf)
(c) csv[writer](csvf) (d) csv_writer(csvf)
52. Choose the correct option for Statement 3 to write the names of the column headings in the CSV file, BOOKS.
CSV.
(a) cw.writerow({‘Title’,’Author’,’Price’}) (b) cw.writerow([‘Title’,’Author’,’Price’])
(c) cw.writerows(‘Title’,’Author’,’Price’) (d) cw.write([‘Title’,’Author’,’Price’])
146 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
53. Which statement will be used to read a csv file in Statement 4.
(a) csvread(csvf) (b) csv.reader(csvf)
(c) csv_reader(csvf) (d) csvf.reader(cs)
54. Fill in the appropriate statement to check the field Title ending with ‘G’ for Statement 5 in the above program.
(a) r[0][-1]==’G’ (b) r[-1][0]==’G’ (c) r[-1][-1]==’G’ (d) r[0][0]==’G’
55. Which statement will be used to call function CSVOpen() in Statement 4.
(a) call CSVOpen() (b) csvf.CSVOpen()
(c) CSVOpen() (d) csvf[CSVOpen]
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 147
MODEL TEST PAPER – 3
(Based on the Latest CBSE Sample Paper)
SECTION - A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Identify invalid variable names out of the following.
(a) for (b) _salary (c) salary12 (d) product
2. Consider a declaration L = “15.6”
Which of the following represents the data type of L?
(a) list (b) tuple (c) float (d) string
3. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print(t[::])?
(a) no output (b) error message
(c) (10, 20, 30, 40, 50, 60, 70, 80, 90) (d) (10)
4. Which of the following options is correct?
(a) The default mode in text file is r (b) The default mode in text file is r+
(c) The default mode in text file is w (d) The default mode in text file is rw
5. Which of the following options can be used to read at most n number of bytes, does not read more than one
line?
(a) myfile = open(‘Myfile.txt’); myfile.read()
(b) myfile = open(‘Myfile.txt’,’r’); myfile.read(n)
(c) myfile = open(‘Myfile.txt’); myfile.readline(n)
(d) myfile = open(‘Myfile.txt’); myfile.readlines()
6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following
options can be used to read from the beginning of the file?
(a) myfile.read() (b) myfile.readline()
(c) myfile.readlines() (d) None of the above
7. Identify the correct option out of the following options to open the binary file in read mode.
(a) myfile = open(‘student’,’rb’) (b) myfile = open(‘student’,’r+b’)
(c) myfile = open(‘student’,’br’) (d) all of the above
8. Choose the correct function Name to check if a string contains only alphabets
(a) alpha() (b) toalpha (c) isalpha() (d) ifalpha()
9. Which is not a valid string?
(a) ‘50’ (b) “50” (c) ‘‘‘50’’’ (d) 50
148 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
10. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?
(a) len(T) (b) count(T) (c) del T (d) max(T)
11. Which type of file stores the data in the same way as stored in the memory?
(a) Text (b) Binary (c) CSV (d) All of the above
12. tell() method takes parameter(s).
(a) 0 (b) 1 (c) 2 (d) 3
13. Which statement is correct to open binary file for writing?
(a) f.open(“file”,wb) (b) f=open(“file”,w+b)
(c) open(f=”file”,bw) (d) f[open(“file”,wb)]
14. In seek(), value sets the reference point at the end of the file.
(a) 0 (b) 1 (c) 2 (d) 3
15. Creating your own function is called
(a) own-defined function (b) in-built function
(c) user-defined function (d) all-defined function
16. Which of the following function header is incorrect?
(a) def xyz(x,y,z) (b) def xyz(x=5,y=30,z=20)
(c) def xyz(x=5,y=30,z) (d) def xyz(x,y=30,z=20)
17. Which of the following is the incorrect way to call a function?
(a) func(15,20) (b) func(a,b) (c) func() (d) func(15,b=20)
18. CSV file can be created in
(a) excel (b) notepad (c) wordpad (d) all of the above
19. Which one is correct option to read csv file from file object f ?
(a) reader(f) (b) f.reader (c) reader.f (d) reader[f]
20. What is the correct expansion of CSV files?
(a) Comma Separated Values (b) Comma Separated Valve
(c) Common Separated Values (d) Common Separation Values
21. Which of the following options is correct?
(a) Open a file for writing only in binary file in wb mode
(b) if we try to open a binary file in wb mode that exists, overwrites the file
(c) if we try to open a binary file in wb mode that does not exist, the file gets Created.
(d) All of the above
22. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print(t[-1:-4])?
(a) (90,80,70,60) (b) (60,70,80,90) (c) (90,80,70) (d) ( )
23. Choose the correct name of the immutable data object from the following:
(a) List (b) Set (c) Tuple (d) Dictionary
24. The file pointer is placed at the end of the file when the file is opened in
(a) r mode (b) w mode (c) a mode (d) all of the above
25. Which is the correct form of declaration of dictionary?
(a) Day={1:’monday’,2:’tuesday’,3:’wednesday’} (b) Day=(1;’monday’,2;’tuesday’,3;’wednesday’)
(c) Day=[1:’monday’,2:’tuesday’,3:’wednesday’] (d) Day={1’monday’,2’tuesday’,3’wednesday’]
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 149
SECTION - B
except EOFError:
pass
file.close()
To fill the missing statement 1, choose the statement to call function Disp
(a) D[Disp()] (b) D.Disp() (c) Disp(D) (d) Disp[D]
34. What will be the output of the following Python code?
def abc():
print(“hello”)
print(“hi”)
print(“bye”)
abc()
(a) hi (b) hi (c) hello (d) bye
hello bye hi hello
bye hello bye hi
35. Evaluate the following expression and identify the correct answer.
a=20*5+3**2%2//5
(a) 101 (b) 100 (c) 1.9 (d) -100
36. 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(20,30))
(a) 100 200 (b) 150 300 (c) 250 50 (d) 250 300
37. Write the output of the following Python code:
def Update(X=10):
X += 15
print( X,end=”#”)
X=20
Update()
print(X)
(a) 25#20 (b) 20#25 (c) 20#20 (d) 25#25
38. What are the possible outcome(s) executed from the following code?
import random
SIDES=[“EAST”,”WEST”,”NORTH”,”SOUTH”];
N=random.randint(1,3)
OUT=””
for I in range(N,1,-1):
OUT=OUT+SIDES[I]
print (OUT)
(a) SOUTHNORTH (b) SOUTHNORTHWEST
(c) SOUTH (d) EASTWESTNORTH
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 151
39. What is the output of the following code snippet?
STR = [‘90’,’10’,’30’,’40’]
COUNT = 3
SUM = 0
for I in [1,2,5,4]:
S = STR[COUNT]
SUM = float (S)+I
print (SUM,end=”,”)
COUNT-=1
(a) 91.0,12.0,35.0,44.0, (b) 32.0,15.0,94.0,41.0
(c) 41.0,32.0,15.0,94.0, (d) 90.0,100.0,130.0,170.0,
40. Suppose content of ‘Myfile.txt’ is
Stay positive and happy
Work hard and don’t give up hope
Be open to criticism and keep learning
Surround yourself with happy, warm and
genuine people
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.readline(2).split()
print(len(record))
myfile.close()
(a) 1 (b) 2 (c) 7 (d) 11
41. Give the output
def makenew(mystr):
newstr = “ “
count = 0
for i in mystr:
if count%2!=0:
newstr= newstr+str(count)
elif i.islower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
newstr = newstr+mystr[:1]
print (newstr)
makenew(“sTUdeNT”)
(a) 1T3D5N71 (b) S1U3E5Ts (c) S1UDE7Ts (d) STUDENTS
42. Suppose content of ‘Myfile.txt’ is
Honesty is the best policy.
Be Honest.
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.readline(35)
print(len(x))
myfile.close()
(a) 28 (b) 30 (c) 35 (d) 38
43. Which of the following options can be used to read the last character of a text file?
(a) file=f.readline() (b) file=f.readlines() (c) file=f.read(-1) (d) file=f.read()
print(file[-1]) print(file[-1]) print(file) print(file[-1])
152 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
44. What are the possible outcome(s) executed from the following code?
import random
PICK=random.randint(0,3)
CITY=[“DELHI”,”MUMBAI”,”CHENNAI”,”KOLKATA”]
for I in CITY:
for J in range(1,PICK):
print(I,end=””)
print()
(i) (ii)
DELHIDELHI DELHI
MUMBAIMUMBAI DELHIMUMBAI
CHENNAICHENNAI DELHIMUMBAICHEN-
KOLKATAKOLKATA NAI
(iii) (iv)
DELHI DELHI
MUMBAI MUMBAIMUMBAI
CHENNAI KOLKATAKOLKATA-
KOLKATA KOLKATA
(a) (i) only (b) (ii) and (iv) (c) (iii) only (d) (i) and (iii)
45. In f=open(“abc.txt”,”w”), “abc.txt” refers to
(a) file name (b) file object (c) file access mode (d) function
46. Observe the following code
File = open(“Mydata”,”a”)
#Blank1
File.close()
Fill the Blank 1 with statement to write “ABC” in the file “Mydata”.
(a) File.write(“ABC”) (b) File.writelines(“ABC”)
(c) File.writedata(“ABC”) (d) File.writes(“ABC”)
47. A folder Test is created in root directory C:\. Two subfolders test1 ,test2 and one “x.txt”
C:\
is created in Test Folder. “y.txt” and “Try.py” are created in folder Test1 and “z.txt” is
created in Test2.
Test
Choose the incorrect option to write single line statement in “Try.py” to open the
“y.txt” file which is stored in same parent folder Test1 using relative path. x.txt
def FilterWords():
c=0
file=open(‘NewsLetter.TXT’, ‘ ’) #Statement-1
line = file. #Statement-2
word = #Statement-3
for c in word:
if : #Statement-4
print(c)
#Statement-5
#Statement-6
50. Write mode of opening the file in statement-1?
(a) a (b) ab (c) w (d) r
51. Fill in the blank in statement-2 to read the data from the file.
(a) File.Read() (b) read() (c) read.lines( ) (d) readlines( )
52. Fill in the blank in statement-3 to read data word by word.
(a) line.Split(“word”) (b) line.split(“w”) (c) line.split() (d) split(line)
53. Fill in the blank in statement-4, which display the word having lesser than 4 characters.
(a) length(c) <4 (b) len(c)<4 (c) c.len ( )<4 (d) len [c ]<3
54. Fill in the blank in Statement-5 to close the file.
(a) file.close() (b) Close(file) (c) file.Close() (d) close(file)
55. Fill in the blank in Statement-6 to call the function FilterWords().
(a) call FilterWords() (b) def FilterWords() (c) FilterWords() (d) file FilterWords()
154 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
MODEL TEST PAPER – 4
(Based on the Latest CBSE Sample Paper)
SECTION - A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Identify invalid variable name(s) out of the following.
(a) While (b) 123salary (c) Big (d) Product
2. Consider a declaration L = 1, ‘Python’, ‘3.14’
Which of the following represents the data type of L?
(a) list (b) tuple (c) float (d) string
3. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print(t[::1])?
(a) no output (b) error message
(c) (10, 20, 30, 40, 50, 60, 70, 80, 90) (d) (10,30,50,70,90)
4. Which of the following options is correct?
(a) Opening file in rb mode means opened a file for reading only in binary format.
(b) Opening file in rb mode, the file pointer is placed at the beginning of the file.
(c) rb mode is the default mode in binary file.
(d) All are correct
5. Which of the following options can be used to read at most n number of bytes, can read more than one line?
(a) myfile = open(‘Myfile.txt’); myfile.read() (b) myfile = open(‘Myfile.txt’,’r’); myfile.read(n)
(c) myfile = open(‘Myfile.txt’); myfile.readline(n) (d) myfile = open(‘Myfile.txt’); myfile.readlines()
6. Which one is correct option to close the file?
(a) f.close (b) f.close() (c) f(close) (d) close(f)
7. Identify the correct option out of the following options to open the binary file for reading and writing both.
(i) myfile = open(‘student’,’rb+’) (ii) myfile = open(‘student’,’wb+’)
(iii) myfile = open(‘student’,’rwb’) (iv) myfile = open(‘student’,rb+wb+)
(a) only (i) (b) both (i) and (iv) (c) both (iii) and (iv) (d) both (i) and (ii)
8. Choose the correct function name required to check if a string contains only lowercase letters.
(a) islower() (b) lower() (c) tolower() (d) onlylower()
9. The expression “5”*3 will return
(a) ‘15’ (b) 15 (c) ’555’ (d) error
10 Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is correct?
(a) T.append(2) (b) T.pop() (c) T.count(10) (d) T.drop(43)
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 155
11. function is used to write in pickle file.
(a) write (b) dump (c) store (d) pick
12. tell() method returns data type.
(a) integer (b) string (c) boolean (d) float
13. Which statetment is correct to unpickle data into list where a is file object, b pickle object and c is the name of
list?
(a) c=b.load(a) (b) a=b.load(c) (c) b=a.load(b) (d) a=c.load(b)
14. Which statement is not valid?
(a) f.seek(0,2) (b) f.seek(2,0) (c) f.seek(1,3) (d) f.seek(3,1)
15. The list of identifiers used in a function call is called
(a) actual parameter(s) (b) formal parameter(s)
(c) value parameter(s) (d) type parameter(s)
16. Which of the following function header is correct?
(a) def prt(p=100, r, t=2) (b) def prt(p=100, r=8, t)
(c) def prt(p, r=8, t) (d) def prt(p, r=8, t=2)
17. Which of the following is the incorrect way to call a function?
(a) func(10,20) (b) func(a=10,b=20)
(c) func(b=20,a=10) (d) func(10,b=20)
18. CSV file can be opened in
(a) excel (b) notepad (c) wordpad (d) all of these
19. method takes 1-dimensional data (one row) to write in csv.
(a) writedata() (b) writeone() (c) writerow() (d) writerows()
20. Which of the following is not a function/method of csv module in Python?
(a) write() (b) reader() (c) writer() (d) writerow()
21. Which of the following options is not correct?
(a) if we try to open text file in r mode that does not exist, an error occurs.
(b) if we try to open file in w mode that does not exist, the file gets created.
(c) if we try to open file in r+ mode that does not exist, no error occurs.
(d) if we try to open file in w+ mode that does not exist, the file gets created.
22. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print(t[-1:-4:-1])?
(a) (90,80,70,60) (b) (60,70,80,90) (c) (90,80,70) (d) ( )
23. Choose the correct name of the mutable data object from the following:
(a) Int (b) Tuple (c) String (d) List
24. The file pointer is placed at the end of the file when the file is opened in
(a) a mode (b) ab mode (c) a+ mode (d) all of these
25. What will happen when new key is same as one of the existing keys in dictionary?
(a) It will overwrite the new value with the old value of the same key.
(b) New value will be added at the end.
(c) Error message will be raised.
(d) New value will be merged with old one under existing key.
156 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
SECTION - B
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 157
32. Which of the following statement(s) is/are correct regarding the file access modes?
(a) ‘r+’ opens a file for both reading and writing. File object points to its beginning.
(b) ‘w+’ opens a file for both writing and reading. Adds at the end of the existing file if it exists and creates
a new one if it does not exist.
(c) ‘wb’ opens a file for reading and writing in binary format. Overwrites the file if it exists and creates a
new one if it does not exist.
(d) ‘a’ opens a file for appending. The file pointer is at the start of the file if the file exists.
33. Function GetStudents() is created to calculate the no of students those have scored more than 75 percentage.
import pickle
def GetStudents():
Countabove75=0
with open(“STUDENT.DAT”,”rb”) as F:
while True:
try:
#1 statement to read from the file
if Countabove75==0:
print(“There is no student who has percentage more than 75”)
else:
print(“no of students who has percentage mroe than 75 = “,Countabove75)
Which of the following commands is used to read each record from the binary file STUDENT.DAT? (marked
as #1 in the Python code?
(a) R = pickle.load(F) (b) pickle.read(r,f) (c) r= pickle.read(f) (d) pickle.load(r,f)
34. Give the output
def abc(a=2,b=4):
return a+b
x=10
y=20
x=abc(x,y)
print(x,y)
(a) 30,20 (b) 6,20 (c) 30,4 (d) 6,4
35. Evaluate the following expression and identify the correct answer.
x=10 > 5 and 7 > 12 or not 18 > 3
(a) True (b) False (c) 0 (d) 1
36. 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(),my_func(20,30))
(a) 300 300 (b) 300 50 (c) 300 290 (d) 250 300
158 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
37. What will be the output of the following code?
value = 50
def display(N):
global value
value = 25
if value/5==5:
value = value + N
else:
value = value - N
print(value, end=’#’)
display(20)
print(value)
(a) 50#45 (b) 50#5 (c) 5#45 (d) 5#50
38. Observe the following Python code and find out which out of the given options (a) to (d) are the expected
correct output(s).
import random
X =[100,75,10,125]
Go = random.randint(0,3)
for i in range(Go):
print (X[i],”$$”,end=””)
(a) 100$$75$$10$$ (b) 75$$10$$125$$
(c) 75$$10$$ (d) 10$$125$$100
39. What is the output of the following code snippet?
L1 = [100,900,300,400,500]
START = 1
SUM = 0
for C in range (START,4):
SUM = SUM + L1[C]
print (C,’:’,SUM)
(a) 4:1600 (b) 3:1600 (c) 4:2100 (d) 3:2100
40. Suppose content of ‘Myfile.txt’ is
Stay positive and happy
Work hard and don’t give up hope
Be open to criticism and keep learning
Surround yourself with happy, warm and genuine people
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.readlines()
rec=record[2].split()
print(len(rec))
myfile.close()
(a) 1 (b) 2 (c) 7 (d) 11
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 159
41. Find and write the output of the following python code:
Text1=”AISSCE 2018” #space between AISSCE and 2018
Text2=””
I=0
while I<len(Text1):
if Text1[I]>=”0” and Text1[I]<=”9”:
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>=”A” and Text1[I] <=”Z”:
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + “*”
I=I+1
print (Text2)
(a) ISSCE *3129 (b) ISSCE*3129 (c) AISSC*3129 (d) ISSCE *018
42. Give the output
Text=”Mind@Work!”
T=””
c=0
for i in Text:
if not i.isalpha():
T=T+”*”
elif not i.isupper():
T=T+(Text[c+1])
else:
T=T+i.upper()
c=c+1
print(T)
(a) Mnd@*Wrk!* (b) Mind@*Wrk* (c) Mid@*Wrk!* (d) Min@Work!*
43. Which of the following is not a file access mode?
(a) rb (b) rb+ (c) wb (d) rw
44. What possible outputs(s) are expected to be displayed on screen at the time of execution of the program from
the following code?
import random
POINTS=[30,50,20,40,45];
BEGIN=random.randint(1,3)
LAST=random.randint(2,4)
for C in range(BEGIN,LAST+1):
print (POINTS[C],”#”,end=””)
160 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
46. When SHORTWORDS() is executed it read lines from a text file WORDBANK.TXT and display those words,
which are lesser than 5 characters.
def SHORTWORDS():
c=0
file=open(‘WORKBANK.TXT’,’r’)
line = file.read()
word = line.split()
for w in word:
if : # statement 1
print (w)
file.close()
Select the appropriate statement to fill the statement 1.
(a) len[w]<5 (b) w.length()<5 (c) w.len()<5 (d) len(w)<5
47. A folder Test is created in root directory C:\. Two subfolders test1, test2 and one
“x.txt” is created in Test Folder. “y.txt” and “Try.py” are created in folder Test1 and C:\
“z.txt” is created in Test2.
Choose the correct option to write single line statement in “Try.py” to open the Test
“z.txt” file which is stored in folder Test2 using relative path
x.txt
(a) f=open(“..\\test2\z.txt”) (b) f=open(“test2\z.txt”)
Test 1 Test 2
(c) f=open(“.\\test2\z.txt”) (d) f=open(“test\\test2\z.txt”)
z.txt
48. If the following code is executed, what will be the output of the following code? y.txt try.py
name=”ComputerSciencewithPython”
print(name[3:10])
(a) mputerS (b) puterSc (c) mputerScie (d) puterScien
49. Give the output
lt2=[[‘one’,’two’,’three’],[5,4,6]]
lt2.reverse()
print(lt2)
(a) [[‘three’, ‘two’, ‘one’],[6,4,5]] (b) [[5, 4, 6], [‘one’, ‘two’, ‘three’]]
(c) [[6,4,5] ,[‘three’, ‘two’, ‘one’]] (d) Error message
SECTION - C
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 161
She has written coding:
def Show_words():
f=open(‘NOTES.TXT’,’ ’) #statement 1
Lines = f. #statement 2
for L in : #statement 3
print( ) #statement 4
#statement 5
162 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
MODEL TEST PAPER – 5
(Based on the Latest CBSE Sample Paper)
SECTION - A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Identify the incorrect variable name.
(a) unit@price (b) fee (c) userid (d) avgmarks
2. Consider a declaration L = ‘Raja123’
Which of the following represents the data type of L?
(a) list (b) tuple (c) float (d) string
3. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print(t[::-1])?
(a) no output (b) error message
(c) (10, 20, 30, 40, 50, 60, 70, 80, 90) (d) (90, 80, 70, 60, 50, 40, 30, 20, 10)
4. Which of the following options is correct?
(a) Opening file in r+ mode means opening a file for reading only.
(b) When file is opened in r+ mode, the file pointer is placed at the beginning of the file.
(c) r+ is the default mode.
(d) all of the above
5. Which of the following options can be used to read the two lines of a text file in the form of string from
Myfile.txt. Assuming the file having two lines only.
(a) myfile = open(‘Myfile.txt’); myfile.read()
(b) myfile = open(‘Myfile.txt’,’r’); myfile.read(2)
(c) myfile = open(‘Myfile.txt’); myfile.readline(2)
(d) myfile = open(‘Myfile.txt’); myfile.readlines()
6. function closes the file and frees the memory space acquired by that file.
(a) close() (b) close (c) closed() (d) closes()
7. Which option is correct when file is opened in ‘a’ mode?
(a) Opens a file for appending.
(b) The file pointer is at the end of the file if the file exists.
(c) If the file does not exist, it creates a new file for writing.
(d) all of the above
8. The return type of the split() function is
(a) string (b) integer (c) list (d) tuple
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 163
9. The expression ‘5’+’5’ will return
(a) ‘55’ (b) ’10’ (c) ’5’’5’ (d) 10
10. Identify the valid arithmetic operator in Python from the following.
(a) ? (b) < (c) // (d) and
11. function is used to read from pickle file in Python.
(a) read (b) readdata (c) pickread (d) load
12. Give the output
f=open(‘c:\\abc.txt’)
g=f.read(5)
t=f.tell()
print(t)
(a) 5 (b) 6 (c) 4 (d) 0
13. Which statement is correct?
(a) import pickle as i (b) import pickles as p
(c) import Pickle as P (d) import Pickles as I
14. Which statement is not valid?
(a) f.seek() (b) f.seek(0) (c) f.seek(1) (d) f.seek(2)
15. The list of parameters used in the function definition is called
(a) actual parameter(s) (b) formal parameter(s)
(c) value parameter(s) (d) type parameter(s)
16. Which of the following function header is correct?
(a) def prt() (b) def prt (c) def prt(0) (d) def prt(1,2)
17. Give the output
def abc(x,y=60):
if x>y:
print(x+y)
else:
print(x-y)
a,b=20,30
abc(b,a)
(a) 50 (b) 80 (c) 90 (d) -30
18. The extension of CSV file is
(a) .csv (b) .cv (c) .cs (d) .sv
19. method takes 2-dimensional data (multiple rows).
(a) writedata() (b) writetwo() (c) writerows() (d) writemany()
20. Which of the following is a function/method of csv module in Python?
(a) read() (b) write() (c) readrow() (d) writerow()
21. Which of the following options is not correct?
(a) if we try to open text file in r mode that does not exist, an error occurs.
(b) if we try to open file in wb mode that does not exist, the file gets created.
(c) if we try to open file in rb+ mode that does not exist, no error occurs.
(d) if we try to open file in wb+ mode that does not exist, the file gets Created.
22. Given a Tuple t= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print(t[3:2:1])?
(a) (30,20) (b) (20,30) (c) (30) (d) ( )
164 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
23. The return type of the len() function is
(a) string (b) integer (c) list (d) tuple
24. Overwrites the file if the file exists when file is opened in
(a) r mode (b) w mode (c) a mode (d) all of these
25. item() method in dictionary takes
(a) no parameter (b) 1 parameter (c) 2 parameters (d) 3 parameters
SECTION - B
166 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
38. What are the possible outcome(s) executed from the following code?
import random
NAV = [“LEFT”,”FRONT”,”RIGHT”,”BACK”]
NUM = random.randint(1,3)
NAVG = “”
for C in range(NUM,1,-1):
NAVG = NAVG+NAV[C]
print (NAVG)
(a) BACKRIGHT (b) BACKRIGHTFRONT
(c) BACK (d) LEFTFRONTRIGHT
39. 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=[ 10,24,16,15]
ChangeVal(L,4)
for i in L :
print(i, end=’#’)
(a) 2#8#4#1# (b) 2#8#16#1# (c) 2#8#16#5# (d) 2#8#16#3#
40. Suppose content of ‘Myfile.txt’ is
You should always
close your files, in some
cases, due to buffering, changes
made to a file may not
show until you close the file
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.read().split(‘,’)
print(len(record))
myfile.close()
(a) 3 (b) 4 (c) 5 (d) 6
41. Find and write the output of the following python code:
Msg1=’WeLcOME’
Msg2=’GUeSTs’
Msg3=’’
for I in range(0,len(Msg2)+1):
if Msg1[I]>=’A’ and Msg1[I]<=’M’:
Msg3=Msg3+Msg1[I]
elif Msg1[I]>=’N’ and Msg1[I]<=’Z’:
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+’*’
print (Msg3)
(a) W*e*SME (b) G*L*TME (c) G*L*T*E (d) W*L*TME
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 167
42. Find the output of the following program :
def ChangeIt(Text,C):
T=””
for K in range(len(Text)):
if Text[K]>=’F’ and Text[K]<=’L’:
T=T+Text[K].lower();
elif Text[K]==’E’ or Text[K]==’e’:
T=T+C;
elif K%2==0:
T=T+Text[K].upper()
else:
T=T+T[K-1]
print(T)
OldText=”pOwERALone”
ChangeIt(OldText,”%”)
(a) PPW%RRLLN% (b) PPWCRRllNC (c) PPW%RRllN% (d) PpW%RrllN%
43. Suppose content of ‘Myfile.txt’ is
Honesty is the best policy.
Be Honest.
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.read()
x=record.count(“Honest”)
print(x)
myfile.close()
(a) 0 (b) 1 (c) 2 (d) 3
44. What possible outputs(s) are expected to be displayed on screen at the time of execution of the program from
the following code?
import random
VAL=[15,25,35,45,55,65,75,85];
From=random.randint(1,3)
To =random.randint(From,4)
for I in range(From,To+1):
print (VAL[I],”*”,)
(a) 35 * 45 * 55 * 65 * 75 * (b) 35 * 45 * 55 *
(c) 15 * 25 * 35 * 45 * (d) 35 * 45 * 55 * 65 *
45. Which statement is correct to open the file using with statement?
(a) with open(‘abc.txt’, ‘w’) to f: (b) open(‘abc.txt’, ‘w’) with f:
(c) f=with open(‘abc.txt’, ‘w’) (d) with open(‘abc.txt’, ‘w’) as f:
46. Divya has written a function countmy( )in Python to read the text file “DATA.TXT” and count the number
oftimes “my” occurs in the file. For example if the file “DATA.TXT” contains: “This is my website. I have
displayed my preferences in the CHOICE section.” The countmy( ) funnction should display the output as
“my occurs 2 times”
def countmy():
f=open(“DATA.TXT”,”r”)
k=f.read()
p=k.split()
#statement 1
print(“my occurs”,c,”times”)
f.close()
Select the appropriate statement to fill the statement 1.
(a) c=k.count(“my”) (b) c=p.count[“my”] (c) p=k.count(“my”) (d) c=p.count(“my”)
168 Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I)
47. A folder Test is created in root directory C:\. Two subfolders test1 ,test2 and one “x.txt”
C:\
is created in Test Folder. “y.txt” and “Try.py” are created in folder Test1 and “z.txt”
is created in Test2.
Choose the correct option to write single line statement in “Try.py” to open the Test
“x.txt” file which is stored in folder Test using relative path.
x.txt
(a) f=open(“x.txt”) (b) f=open(“.\\x.txt”)
Test 1 Test 2
(c) f=open(“test\\x.txt”) (d) f=open(“..\\x.txt”)
48. Write the value of sum1 after execution of the following WHILE loop : z.txt
y.txt try.py
i = 1
sum1 = 0
while i<10:
sum1 =sum1+ i
i =i+2
(a) 24 (b) 25 (c) 26 (d) 27
49. What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2]=3.14
print(tup1)
(a) (1,2,[3.14],3) (b) (1,2,3.14,3) (c) (1,2,[1,2,3.14],3) (d) Error Message
SECTION - C
Score Plus Question Bank with CBSE Sample Paper and Model Test Papers in Computer Science-12 (Term I) 169
52. Identify the function (with argument), to be
used at blank space in line marked as
Statement-3.
(a) load() (b) f.load() (c)
load(f) (d)
f(load)
53. What will be the suitable code for blank space in line marked as
Statement-4.
(a) rec(0)==r (b) rec[1]==’r’ (c) rec[1]==r (d) rec[0]=
54. What will be the suitable code for blank space in line marked as
Statement-5 to show record?
(a) show(rec) (b) print(rec) (c) print.rec() (d) rec(pri
55. Which statement Arun should use at blank space in line marked as
Statement5 to close the file?
(a) file.close() (b) close(file) (c) f.close() (d) close()