Page 368 - C++
P. 368
CBSE AISSCE 2017-2018 Marking Scheme for Computer Science
(2018-2019 Sub Code: 083 Paper Code: 91)
Ans def display1():
c=0
file=open('INDIA.TXT','r')
c=0
for LINE in file:
Words = LINE.split()
for W in Words:
if W=="India":
c=c+1
print c
file.close()
OR
def display():
c=0
file=open('INDIA.TXT','r')
lines = file.read() # lines = file.readline()
while lines:
words = lines.split()
for w in words:
if w=="India":
c=c+1
lines = file.read() # lines = file.readline()
print c
file.close()
(½ Mark for opening the file)
(½ Mark for reading all lines, and dividing it into words)
(½ Mark for checking condition and incrementing count)
(½ Mark for displaying count)
Note: Ignore if try: except:
(c) Considering the following definition of class MULTIPLEX, write a method in python 3
to search and display all the content in a pickled file CINEMA.DAT, where MTYPE is
matching with the value ‘Comedy’.
class MULTIPLEX:
def __init__(self,mno,mname,mtype):
self.MNO = mno
self.MNAME = mname
self.MTYPE = mtype
def Show(self):
print self.MNO:"*",self.MNAME,"$",self.MTYPE
Ans def Search():
file=open('CINEMA.DAT','rb')
try:
while True:
M=pickle.load(file)
if M.MTYPE=="Comedy":
M.Show()
except EOFError:
pass
Page #26/35