Set 1 Comp. Sci Ans. Key
Set 1 Comp. Sci Ans. Key
MARKING SCHEME
Max. Marks : 35
SECTION-A
1. True
(1 mark for correct answer)
2. False
(1 mark for correct answer)
3. d) as
(1 mark for correct answer)
4. c) When no exception occurs
(1 mark for correct answer)
5. a) 6.0
(1 mark for correct answer)
6. b) [45, 60]
(1 mark for correct answer)
7. b) File.seek(-10,2)
(1 mark for correct answer)
8. d) are
(1 mark for correct answer)
9. b) Both A and R are true and R is not the correct explanation for A
(1 mark for correct answer)
SECTION-B
10. 115@67@
(2 marks for correct output)
11. a) and b)
Highest and Lowest Values of the label VALUE are as follows:
Highest =13
Lowest=4
(1 mark for possible outputs)
(1 mark for Highest and lowest values)
12. def COUNTLINES():
f=open("ESSAY.TXT","r")
count=0
L=f.readlines()
for line in L:
if line[0] not in 'aeiouAEIOU':
count+=1
print("Number of lines not starting with any vowel is / are = ", count)
f.close()
( ½ Mark for correctly opening the file and reading content of file )
( ½ Mark for the correct loop)
( ½ Mark for correct logic)
( ½ Mark for correctly printing output and closing of file)
13 def CountDigits( ):
f=open("MyData.TXT","r")
s=f.read( )
count=0
for ch in s:
if ch.isdigit( ):
count+=1
print("No. of digits are: ", count)
f.close( )
( ½ Mark for correctly opening the file and reading content of file )
( ½ Mark for the correct loop)
( ½ Mark for correct logic)
( ½ Mark for correctly printing output and closing of file)
SECTION-C
14 def ShowInLines():
f=open("STORY.TXT",'r')
S=f.read()
for W in S:
if W=="." or W=="?" or W=="!":
print(W)
elif W=="\n":
print(end="")
else:
print(W,end="")
f.close()
OR
def LINESTARTS_H():
f=open("News.TXT","r")
L=f.readlines( )
count=0
for line in L:
if line[0]=='h' or line[0]=='H':
count+=1
print("No. of lines start with character H are: ", count)
f.close( )
SECTION-D
15 i.
Pickling: Pickling is the process whereby a Python object hierarchy is
converted into a byte stream.
Unpickling: A byte stream is converted into object hierarchy.
( 1 Mark for correct definition of pickling)
( 1 Mark for correct definition of unpickling)
ii.
import pickle
def CountRecord(Brand):
f=open("PRODUCT.dat", 'rb')
L=pickle.load(f)
count=0
for D in L:
if D[“brand”]==Brand:
count+=1
f.close( )
return count
ii.
import pickle
def Display_Record():
f=open("STUDENT.DAT","rb")
L=pickle.load(f)
for D in L:
if D['Marks']>=80 and D['Marks']<=95:
print(D["SName"])
f.close()
ii.
import pickle
def Delete_Record():
f=open("PLAYER.DAT","rb+")
L=pickle.load(f)
M=[]
found=0
for D in L:
for pid in D:
if D[pid][1]>18:
found=1
else:
M.append(D)
if found==1:
f.seek(0)
pickle.dump(M,f)
print("Data deleted successfully")
else:
print("No player found whose age is more than 18")
f.close()
OR
i.
Absolute path: This is the path of a file in a system which starts from the
root of the file system. It describes the location of a file regardless of the
current working directory. Example: "D:\\python programs\\Book.txt".
Relative path: This is the file path without slash. It describes the location of
a file in relative to the current working directory. Example: “Book.txt”.
( 1 Mark for correct definition of absolute path)
( 1 Mark for correct definition of relative path)
ii.
import pickle
def Modify_Song(s_id):
f=open("SONG.DAT","rb+")
L=pickle.load(f)
M=[]
found=0
for D in L:
for key in D:
if key==s_id:
found=1
D[key][2]=2020
M.append(D)
if found==1:
f.seek(0)
pickle.dump(M,f)
print("Data updated successfully")
else:
print("No song found ")
f.close()
(½ Mark for opening the file in correct mode)
(½ Mark for to read the content of file)
(½ Mark for correct loop)
(1 Mark for correct condition or logic)
(½ Mark for use of seek and dump functions)
17 i.
Text File Binary File
Stores information in ASCII Stores information in the same
characters. format which the information is held
in memory.
Slower than binary files. Binary files are faster and easier for
a program to read and write the text
files.
File extension : .txt File application: as per application
ii.
import pickle
def Add_Record():
f=open("PEOPLE.DAT", "wb")
n=int(input("How many records you want to add: "))
M=[]
for i in range(n):
Adhaar_number=int(input("Adhaar Number: "))
Name=input("Enter Name: ")
Gender=input("Enter gender: ")
Age=int(input("Enter Age: "))
L=[Adhaar_number, Name, Gender, Age]
M.append(L)
pickle.dump(M,f)
print("Data added successfully")
f.close()
(½ Mark to import pickle module and header of the function )
(½ Mark for opening the file in correct mode)
(½ Mark for input from user and creation of empty list)
(1 Mark for correct loop and taking values from user and creation and appending the list)
(½ Mark for to use dump function)
OR
i.
• Storage Efficiency: Binary files use less storage. Text file uses
additional formatting and encoding.
• Binary files are faster than text files.
• Binary files can store complex data like images, audio etc. whereas text
files are suitable for simple textual format.
(2 marks for correct answer)
ii.
import pickle
def Copy_Book():
f=open("BOOK.DAT", "rb")
L=pickle.load(f)
M=[]
found=0
for record in L:
if record[3]>400:
M.append(record)
found=1
f.close()
fout=open("NEWBOOK.DAT", "wb")
pickle.dump(M,fout)
print("Records successfully copied")
fout.close()