You are on page 1of 6

Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme

Time: 3 Hours Maximum Marks: 70


• Section A has 18 questions carrying 01 mark each
• Section B has 7 Very Short Answer type questions carrying 02 marks each
• Section C has 5 Short Answer type questions carrying 03 marks each
• Section D has 3 Long Answer type questions carrying 05 marks each
• Section E has 2 questions carrying 04 marks each

SECTION A
1. Identify the sequence data type of Python. [1]
a) str b) float c) int d) complex

2. Identify the correct keyword. [1]


a) none b) None c) true d) FALSE

3. Identify the incorrect string literal. [1]


a) 'Bye' b) "Bye" c) '''Bye"' d) '"Bye"'

4. Identify the incorrect Python statement. [1]


astr='Delli'
a) astr='Delhi' b) print(astr) c) astr*=4 d) astr[3]='h'

5. Identify a function that does not belong to math module. [1]


a) round() b) comb() c) perm() d) gcd()

6. Identify a function which is not a string method. [1]


a) find() b) clear() c) count() d) format()

7. Identify the statement that will trigger an error. [1]


a) print(max(-5.7,-2.4,-2.9)) b) print(max('75','AC','**'))
c) print(max(45,'35',6.2)) d) print(max(52,68,47))

8. Give the correct output. [1]


print(eval('5+3**2*2-12/4'))
a) 83.0 b) 83 c) 20 d) 20.0

9. Give the correct output. [1]


print('RED' or True and 45.2)
a) RED b) True c) 45.2 d) Error

10. Identify the statement that will display False. [1]


a) print('WXYZ567'.isupper()) b) print('XY+89a'.isupper())
c) print('ABCDEF'.isupper()) d) print('PQR*-+'.isupper())

11. Identify the correct function from pickle module. Error in question
[1]
a) close() b) writerows() c) reader() d) writerow()

12. Identify the correct statement. [1]


fo=open('MYNOTES.TXT', 'rt')
a) fo.dump(50) b) fo.write(50) c) fo.load(50) d) fo.read(50)

13. Identify the mode when file pointer is at the end of the file. [1]
a) 't+a' b) 'r+t' c) 't+w' d) 'rt+'
Page 1 / 4
Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme
14. Parameter used to change the default separator using writer() function of csv module is . [1]
a) delim b) delimiter c) separator d) sep

15. Identify the correct statement. [1]


a) Method tell() returns float b) Method tell() returns None
c) Method tell() returns int d) Method tell() moves file pointer

16. Identify the statement, that moves file pointer to the end of the file. [1]
fo=open('MYNOTES.TXT', 'rt')
a) fo.seek(1,0) b) fo.seek(2,0) c) fo.seek(0,1) d) fo.seek(0,2)

Question Numbers 17 and 18 are Assertion (A) and Reasoning (R) based questions. Mark the correct
choice as:
a) Both A and R are both true and R is the correct explanation for A
b) Both A and R are true, but R is not the correct explanation for A
c) A is true but R is false
d) A is false but R is true
17. Assertion (A): Keyword break terminates a Python loop. [1]
Reasoning (R): Keyword return terminates a Python function. Ans. B

18. Assertion (A): In a Python function, number of actual parameters must be equal to number of formal
parameters. [1]
Reason (R): In a Python function, number of actual parameters must be equal to number of default
parameters. Ans C

SECTION B
19. Kunal has written a Python script to check for a Harshad Number. But his code is having few errors.
Rewrite the Python script after removing all the errors and underline the corrections. [2]
t=n=int(input('Integer? ') )
s=0
While t: # while t:
s+t%10=s t//=10 # s=s+t%10
if n%s==0: print('Harshad No.')
: print('Not Harshad No.') # else:

20. After the execution of Python program given below, what will be the possible correct output(s)? What
will be the maximum value and minimum value stored in the variable pos? [2]
from random import randrange
alist=(321,432,543,654,765,876]
for k in range(3):
pos=randrange(3)+3
print(alist[pos], end="")
a) 321432543 b) 765876654 c) 876654765 d) 765654543

21. Give the output of the Python code given below: [2]
def foo(a, b):
if a>b: x, y=a*b, 3*a-b 75 40
else: x, y= 5*b//a, 7*b-a
print(x, y) 15 100
p, q=15, 5
foo(p, q)
foo(q, p)

Page 2 / 4
Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme
22. Give the output of the Python script given below: [2]
astr='INTE-rnet#ExTr*AnEt'; bstr=""
for k in range(len(astr)):
if 'A'<=astr[k]<='Z': bstr=bstr+astr[k+1]
elif 'a'<=astr[k]<='z': bstr=bstr+astr[k-1]
else: bstr=bstr+':'
print(bstr) NTE-:-rne:xErT:nAtE

23. Name any four tokens supported by Python. [2]


Keyword, Identifier, Literal, Operator, Delimiter

24. Write any two differences between Python's function sorted() and list method sort(). [2]
sorted() is built in function sort() is List Method
sorted does not change original index sort() change the original index

25. Write any two differences between Python's mutable data type and immutable data type. [2]
Mutable datatype can be changed immutable data type can not be changed
Mutable Data Type pass as reference immutable data type passed as value
List string, tuple,int,float,bool,complex

SECTION C
26. Write a Python script to create a dictionary employee with following keys:
code integer (employee code)
name string (employee name)
bsal floating point (monthly basic salary)
Append following keys in the dictionary employee:
bonus floating point (yearly bonus)
hrent floating point (house rent)
Basic Salary Bonus House Rent
<=100000 20% of Basic Salary 10% of Basic Salary
>100000 and <=300000 15% of Basic Salary 12.5% of Basic Salary
>300000 and <=5000000 12.5% of Basic Salary 15% of Basic Salary
>500000 10% of Basic Salary 20% of Basic Salary
Input values for keys code, name and bsal. Calculate values for keys bonus and hrent. Display
dictionary employee on the screen using a loop. DO IT YOURSELF [3]

27. Write a Python function togglestr(), to convert lowercase to uppercase and uppercase to
lowercase, for all alphabets present in the string. Display the toggled string, number of lowercase
converted to uppercase and number of uppercase converted to lowercase. The string that is to be toggled
is passed as a parameter to the function. Do not use any string methods. DO IT YOURSELF [3]

28. Write a Python function countchars(), to read a text file ESSAY.TXT. Count and display number of
white-space characters and total number of alphanumeric characters present in the text file. [3]
def countchars():
fr=open('Essay.txt', 'r')
data=fr.read()
c1=c2=0
for ch in data:
if ch.isalnum(): c1+=1
if ch in " \n\t": c2+=1
fr.close()
print('Number of alphanumeric characters=',c1)
print('Number of white space characters=',c2)

Page 3 / 4
Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme
29. Write a Python function countwords(), to read a text file ESSAY.TXT. Count and display number of
words starting with vowels present in the text file. Ignore case when counting vowels. [3]
def countwords():
fr=open('Costo.txt', 'r')
data=fr.read()
fr.close()
words=data.split()
c=0
for v in words:
if v[0] in 'aeiouAEIOU':
c+=1
print('Number of words starting with Vowels=',c)

30. Write a Python function countlines(), to read a text file ESSAY.TXT. Count and display number of
lines starting with consonants present in the text file. Ignore case when counting consonants. [3]
def countwords():
fr=open('Costo.txt', 'r')
data=fr.read()
fr.close()
lines=data.split(‘\n’)
c=0
for l in lines:
if l[0].isalpha() and l[0] not in 'aeiouAEIOU':
c+=1
print('Number of lines starting with consonants=',c)

SECTION D
31. a) Give the output of the Python code given below: [2]
alist=[14, 75, 28, 86, 49, 64, 91, 37]
for x in range(len(alist)): 89$164$114$200$113$177$128$165$
if alist[x]%7==0:
alist[x]+=alist[x+1]
else:
alist[x]+=alist[x-1]
for ele in alist: print(ele,end='$')

b) Write a Python function listmaxmin(), to find and display a) largest value and its position present
in the list b) smallest value and its position present in the list. Don’t use any list methods, max(),
min() and sorted(). List is passed as a parameter to the function. [3]
def listmaxmin(list1):
max1=min1=list1[0]
maxpos,minpos=0,0
for k in range(len(list1)):
if list1[k]>max1:
max1=list1[k]
maxpos=k
if list1[k]<min1:
min1=list1[k]
minpos=k
print("Maximum Value =",max1,"present at index=",maxpos)
print("Minimum Value =",min1,"present at index=",minpos)

Page 4 / 4
Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme
32. A CSV file MARKS.CSV contain student's data and every record has following fields:
ROLL,NAME,AGG1,AGG2 where ROLL is int, NAME is str, AGG1 (1st Term aggregate) is float
and AGG2 (2nd term aggregate) is float
a) Write a Python function addstu(), to add a new record in the CSV file MARKS.CSV by taking
input from the keyboard during the run-time. [2]
import csv
def addstu():
f=open('MARKS.CSV',’a’,newline=’’)
fw=csv.writer(f)
roll=int(input(“Roll:”))
name=input(“Name:”)
agg1=int(input(“AGG1:”))
agg2=int(input(“AGG2:”))
rec=[roll,name,agg1,agg2]
fw.writerow(rec)
f.close()

b) Write a Python function findstu(), to read the CSV file MARKS.CSV and display those records
where AGG1<200 andAGG2<200. If no such record is found, then display an appropriate message.[3]
import csv
def findstu():
fr=open('MARKS.CSV')
records=csv.reader(fr)
c=0
for rec in records:
if int(rec[2])<200 and int(rec[3])<200:
print(rec[0],rec[1],rec[2],rec[3])
c+=1
if c==0: print(“No Records Found”)
else: print(“No of records found=”,c)

33. A binary file EMPSAL.DAT contains employee's record as a list: [CODE,NAME,GSAL,ITAX]


where CODE is int, NAME is str, GSAL is float and ITAX is float
a) Write a Python function addemp(), to append a new record in the binary file EMPSAL.DAT by
taking input from the keyboard during the run-time. [2]
import pickle
def addemp():
f=open("EMPSAL.DAT",'ab')
code=int(input(“Code:”))
name=input(“Name:”)
gsal=int(input(“GSAL:”))
itax=int(input(“Itax:”))
rec=[code,name,gsal,itax]
pickle.dump(rec,f)
f.close()

b) Write a Python function showemp(), to read the binary file EMPSAL.DAT and display those
records where GSAL–ITAX < 300000. Also display number of such records found. [3]
import pickle
def searchRec():
f=open("EMPSAL.DAT",'rb')
c=0
try:
while True: Page 5 / 4
Class XII Computer Science First Term Exam 2023-24 Sample Paper Marking Scheme
rec=f.load(df)
if rec[2]-rec[3]<300000:
c+=1
print(rec[0],rec[1],rec[2],rec[3],sep= " ")
if c!=0:
print("Number of Records =",c)
else:
print("No Records found")
df.close()

SECTION E
34. a) Write any two differences between text file and binary file. [2]
o Text file is human readable Binary file is not human readable
o Text file can be open and edited Binary file can not be edited in text
editor in any text editor
o Newline(‘\n’) & EOF character conversion No conversion takes place
takes place

b) Content of the text file IPL.TXT is given below with position of the file pointer after end of very line
is given in the middle column. Give the output of Python script given below: [2]
GT ,13,9,4,18 15 with fobj=open('IPL.TXT') as fobj:
CSK,13,7,5,15 30 for pos in range(45,-1,-15):
LSG,13,7,5,15 45 fobj.seek(pos)
MI ,13,7,6,14 60 print(fobj.readline(),end="")

Ans MI ,13,7,6,14
LSG,13,7,5,15
CSK,13,7,5,15
GT ,13,9,4,18

35. A CSV data file 'ITEMS.CSV' contains item records where every record has following fields: code,
item, price, quantity. A record to be deleted from the CSV file by using a temporary file. Complete the
Python code by filling the missing blanks. [4]
from csv import reader, writer #import the correct functions
from os import rename, remove
fr=open(‘ITEMS.CSV’,’r’) #open ITEMS.CSV in read mode
fw=open('TEMP.CSV',’w’,newline=’ =’ ‘‘)) #write the missing
data=reader(fr) parameters
cwobj=writer(fw)
found=False #creates the writer object
code=input('Code to Delete? ')
for rec in fr: : #write the missing iterator object
if code==rec[0]:

print('Record Deleted!)
found-True #update the flag variable
else:
fw.writewow(rec) #write rec into TEMP.CSV
fr.close()
fw.close()
remove(‘ITEMS.CSV’) #deletes ITEMS.CSV
rename('TEMP.CSV', 'ITEMS.CSV')

if not found: print('Record not Found!)

Page 6 / 4

You might also like