G 12 Model 2 Cs Ms-Pcbcs
G 12 Model 2 Cs Ms-Pcbcs
MODEL – 2-EXAMINATION
B C S )
MARKING SCHEME
SECTION – B (7 X 2 = 14 MARKS)
A mutable object can be updated whereas an immutable object cannot be updated.
22
Mutable object: [1,2] or {1:1,2:2} (Any one)
Immutable object: (1,2) or ‘123’ (Any one)
(1 mark for correct difference)
(½ x 2 = 1 Mark for example)
I) Logical operators: AND,OR,NOT
23 (II) Relational operators: >, >=
(½ x 4 = 2 Marks for each correct operator)
(i) L1.insert(2,200)
24 (ii) message.endswith('.')
OR
import statistics
print( statistics.mode(studentAge) )
(1 mark for correct answer)
(A), (C) (½ x 2 = 1 Mark)
25
Minimum and maximum possible values of the variable b: 1,3 (½ x 2 =
1 Mark)
26
(½ Mark for correctly identifying and correcting each of the four errors)
4*L
27 33*4
21*S
10*6
(1/2 Mark for each line correct output)
(OR)
7#14#6#7#
(½ mark for the correct digit with a #)
oLYMPIC#gAMES# 202
28
(2 Mark for writing the correct output)
(OR)
1#
(2 Mark for writing the correct output)
SECTION – C (3 X 3 = 9 MARKS)
29
SECTION – D (4 X 4 = 16 MARKS)
(A) &&lEARNingpytHON
32 (3 marks for writing the correct output)
(B)
si no (1 mark for correct output)
import csv
33 def add():
fout=open("furdata.csv","a",newline='\n')
wr=csv.writer(fout)
fid=int(input("Enter Furniture Id :: "))
fname=input("Enter Furniture name :: ")
fprice=int(input("Enter price :: "))
FD=[fid,fname,fprice]
wr.writerow(FD)
fout.close()
def search():
fin=open("furdata.csv","r",newline='\n')
data=csv.reader(fin)
found=False
print("The Details are")
for i in data:
if int(i[2])>10000:
found=True
print(i[0],i[1],i[2])
if found==False:
print("Record not found")
fin.close()
add()
print("Now displaying")
search()
(II)
def Count_records():
import csv
f=open("happiness.csv",'r')
records=csv.reader(f)
count=0
for i in records:
count+=1
print(count)
f.close()
SECTION – E (2 X 5 = 10 MARKS)
(A)
36 Advantage of a csv file:
* It is human readable – can be opened in Excel and Notepad
applications
* It is just like text file
(B)
import pickle
def WRITEREC():
f = open("PLANTS.dat","wb")
data_log = []
while True:
ID = int(input("Enter ID:"))
NAME = input("Enter Name:")
PRICE = float(input("Enter Price:"))
data_log.append([ID,NAME,PRICE])
Choice=input("Do you want to add more? (Yes/No) : ")
if Choice[0].lower()=='n':
break
pickle.dump(data_log,f)
f.close()
def SHOWHIGH():
f = open("PLANTS.dat","rb")
try:
while True:
data= pickle.load(f)
for record in data:
if record[2]>500:
print("ID:",record[0])
print("Name:",record[1])
print("Price:",record[2])
print()
except:
f.close()
(A)
37 Difference between binary file and csv file: (Any one difference may be given)
Binary file:
Extension is .dat
Not human readable
Stores data in the form of 0s and 1s
CSV file
Extension is .csv
Human readable
Stores data like a text file
(B)
import pickle
def countrec():
f = open("PATIENTS.dat","rb")
N=0
try:
while True:
data= pickle.load(f)
for record in data:
if record[2]=='COVID-19':
print("PID:",record[0])
print("NAME:",record[1])
print("DISEASE:",record[2])
N += 1
except:
f.close()
print('Total number of Covid-19 Patients = ', N)
(½ mark for function definition)
(½ mark for opening the file in correct mode)
(1 mark for reading the binary file)
(1 mark for the traversal loop)
(½ mark for checking the COVID-19 condition)
(½ mark for displaying the matched records)
(½ mark for displaying the final value of the Counter Identifier)