COMPUTER SCIENCE(083)
UNIT TEST -II 2022-23 (CLASS-XII )
Time allowed: 1:30 hours Maximum Marks:
40
GENERAL INSTRUCTIONS:
i. The question paper is divided into 4 sections – A, B, C and D
ii. Section A, consists of 4 questions. Each question carries 5 marks.
iii. Section B, consists of 4 questions. Each question carries 1 mark.
iv. Section C, consists of 6 questions. Each question carries 2 marks.
v. Section D, has 1 question of 4 marks.
vi. Internal choices have been given for question numbers 15
SECTION-A
Competency Based Question
Q1. Arun, during Practical Examination of Computer Science, has been assigned an incomplete search() function
to search in a pickled file [Link]. The File [Link] is created by his Teacher and the following information
is known about the file.
• File contains details of students in [roll_no,name,marks] format.
• File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student is written
in the binary file using dump(). Arun has been assigned the task to complete the code and print details of roll
number 1.
def search():
f = open("[Link]",____) #Statement-1
____: #Statement-2
while True:
rec = pickle.____ #Statement-3
if(____): #Statement-4
print(rec)
except:
pass
____ #Statement-5
Q(i)In which mode Arun should open the file in Statement-1?
a) r b) r+ c) rb d) wb
Q(ii). Identify the suitable code to be used at blank space in line marked as Statement2 a) if(rec[0]==1)
b) for i in range(10) c) try d) pass
Q(iii). Identify the function (with argument), to be used at blank space in line marked as Statement-3.
a) load() b) load([Link]) c) load(f) d) load(fin)
Q(iv). What will be the suitable code for blank space in line marked as Statement-4.
a) rec[0]==2 b) rec[1]==2 c) rec[2]==2 d) rec[0]==1
Q(v). Which statement Arun should use at blank space in line marked as Statement4 to close the
file.
a) [Link]() b) close(file) c) [Link]() d) close()
Q2. Radha Shah is a programmer, who has recently been given a task to write a python code to perform the
following CSV file operations with the help of two user defined functions/modules:
a. CSVOpen() : to create a CSV file called [Link] in append mode containing information of books
– Title, Author and Price.
b. CSVRead() : to display the records from the CSV file called [Link] where the field title starts
with 'R'. She has succeeded in writing partial code and has missed out certain statements, so she has left certain
queries in comment lines.
import csv
def CSVOpen():
with open('[Link]','______',newline='') as csvf: #Statement-1
cw=______ #Statement-2
______ #Statement-3
[Link](['Rapunzel','Jack',300])
[Link](['Barbie','Doll',900])
[Link](['Johnny','Jane',280])
def CSVRead()
try:
with open('[Link]','r') as csvf:
cr=______ #Statement-4
for r in cr:
if ______: #Statement-5
print(r)
except: print('File Not Found')
CSVOpen()
CSVRead()
You as an expert of Python have to provide the missing statements and other related queries based on the following
code of Radha. Answer any four questions (out of five) from the below mentioned questions.
Q(i).Choose the appropriate mode in which the file is to be opened in append mode (Statement 1)
a. w+ b. ab c. r+ d. a
Q(ii). Which statement will be used to create a csv writer object in Statement 2.
a. [Link](csvf) b. [Link](csvf) c. [Link]() d. [Link](csvf)
Q(iii). Choose the correct option for Statement 3 to write the names of the column headings in the CSV file,
[Link].
a. [Link]('Title','Author','Price') b. [Link](['Title','Author','Price'])
c. [Link]('Title','Author','Price') d. [Link](['Title','Author','Price'])
Q(iv). Which statement will be used to read a csv file in Statement 4.
a. [Link](csvf) b. [Link](csvf)
c. [Link]() d. [Link](cs)
Q(v). Fill in the appropriate statement to check the field Title starting with „R‟ for Statement 5 in the above
program.
a. r[0][0]=='R' b. r[1][0]=='R' c. r[0][1]=='R' d. d) r[1][1]=='R'
Q3. Your teacher has given you a method/function FilterWords() in python which read lines from a text file
[Link], and display those words, which are lesser than 4 characters. Your teachers intentionally kept few
blanks in between the code and asked you to fill the blanks so that the code will run to find desired result. Do the
needful with the following python code.
def FilterWords():
c=0
file=open('[Link]', '_____') #Statement-1
line = file._____ #Statement-2
word = _____ #Statement-3
for c in word:
if _____: #Statement-4
print(c)
_________ #Statement-5
FilterWords
Q(i)Write mode of opening the file in statement-1?
a. a b. ab c. w d. r
Q(ii) Fill in the blank in statement-2 to read the data from the file.
a. [Link]() b. [Link]() c. [Link]( ) d. readlines( )
Q(iii) Fill in the blank in statement-3 to read data word by word.
a. [Link]() b. [Link]() c. [Link]() d. [Link]()
Q(iv) Fill in the blank in statement-4, which display the word having lesser than 4 characters.
a. len(c) ==4 b. len(c)<4 c. len ( )= =3 d. len ( )==3
Q(v) Fill in the blank in Statement-5 to close the file.
a. [Link]() b. [Link]() c. Close() d. end()
Q4. Rohit, a student of class 12th, is learning CSV File Module in Python. During examination, he has been
assigned an incomplete python code (shown below) to create a CSV File '[Link]' (content shown below).
Help him in completing the code which creates the desired CSV File.
CSV File
1,AKSHAY,XII,jnv
2,ABHISHEK,XII,kv
3,ARVIND,XII,jnv
4,RAVI,XII,jnv
5,ASHISH,XII,kv
Incomplete Code
import_____ #Statement-1
fhe = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = [ ]
header = ['ROLL_NO', 'NAME', 'CLASS', 'SCHOOL']
[Link](header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
School = input("Enter SCHOOL : ")
rec = [_____] #Statement-4
[Link](rec)
stuwriter. _____ (data) #Statement-5
[Link]()
Q(i)Identify the suitable code for blank space in line marked as Statement-1.
a) csv
b) CSV
c csv file
d) Csv
Q(ii)Identify the missing code for blank space in line marked as Statement-2?
a) "[Link]","w"
b) "[Link]","w"
c) "[Link]","r"
d) "[Link]","r"
Q(iii) Choose the function name (with argument) that should be used in the blank space of line marked as
Statement-3
a) reader(fhe)
b) reader(MyFile)
c) writer(fhe)
d) writer(MyFile)
Q(iv) Identify the suitable code for blank space in line marked as Statement-4.
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
b) ROLL_NO, NAME, CLASS, SECTION
c) 'roll_no','name','Class','School'
d) roll_no,name,Class,School
Q(v)Choose the function name that should be used in the blank space of line marked as Statement-5 to
create the desired CSV File?
a) dump() b) load() c) writerows() d) writerow()
SECTION-B
Q5. Which of the following mode in file opening statement results or generates an error if the file does not exist?
(a) a+ (b) r+ ( c) w+ (d) None of the above
Q6. 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)
Q7. The readlines( ) methodsreturns
(a) str (b) a list of lines (c)a list of single characters (d) a list of integers.
Q8. Which method is used to read all the characters?
(a) read( ) (b)readchar() (C) readall() (d) readchar()
SECTION-C
Q9. Differentiate between text and binary file with examples.
[Link] the error in the following code.
import csv
f=open("[Link]" )
csv_f=[Link](f)
Q11. .Identify the error in the following code.
import pickel
d=['one',2,[3,4,5]]
with open('[Link]','wb' :
[Link](d)
Q12. What is seek( ) and tell( ) function explain with suitable example.
Q13. Write a function ATCount() in Python, which should read each character of a text file “[Link]”
and then count and display the count of occurrence of alphabets A and T individually (including small cases e and t
too).
Example:
If the file content is as follows:
Today is a pleasant day. It might rain today. It is mentioned on weather sites
The ATCount() function should display the output as: A or a: 8 T or t : 9
Q14. What is the difference between the following set of statements (a) and (b):
a) P = open(“[Link]”,”r”)
[Link](10)
b) with open(“[Link]”, “r”) as P:
x = [Link]()
SECTION-D
[Link] a method COUNTLINES() in Python to read lines from text file „[Link]‟ and display the lines
which are starting with vowel.
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone‟s safety.
A marked difference will come in our country.
The COUNTLINES() function should display the output as:
The number of lines not starting with any vowel - 2
OR
Write a program to enter the following records in a binary file:
Item No integer
Item_Name string
Qty integer
Price float
Number of records to be entered should be accepted from the user. Read the file
to display the records in the following format:
Item No:
Item Name :
Quantity:
Price per item:
Amount: ( to be calculated as Price * Qty)
--End of the question paper--