CS Practice Paper
CS Practice Paper
of pages - 12
(M)
MID-TERM EXAMINATION (2023-24)
CLASS:XII
SUBJECT: COMPUTER SCIENCE (083)
Time Allowed :3 hours
Maximum Marks : 70
GENERAL INSTRUCTIONS:
Please check this questionpaper contains 35 questions.
The paper is divided into 5 Sections- A, B, C, D and E.
" Section A, consists of 18 questions (1 to 18). Each
question carries 1 Mark.
Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
Section D, consists of 2questions (31 to 32). Each question carries 4 Marks.
Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
Allprogramming questions are to be answered using Python Language only.
SECTION-A
1. State True or False:
a. True . b. False
C. None d. Null
1
XII-COMPUTER SC.-M
'sing a mg mula tr caleulation generates a
Smtay (b Semuntie Eeror
logial Run tme Brror
True#Falso
atsewalse d. False#*True
retum n #Statement 6
Statement 2 b. Statement 3
C. Statement 4 d. Statement 5
10. The statement terminates the execution of the while loop.
a. Continue b break
C. exit d pass
11. Identify the type of error in the following: a =5/0
a Syntax Error b Semantic Error
C. Logical Error d. Runtime Error
12. What will be the output of the following Python code?
X=8
def Change(N):
global X
X=3 N=8
X, N= N, X
print(X, N, sep =9%', end ='@)
3/.8 3
Change(3)
print(X)
3%8@3 b. 3@8%8
C 8%8@8 d. 3%3@3
3 XII-COMPUTER SC.-M
13. Suppose L |3,4,5,20,4,5|. whut is I. atlcr L.pop(4)?
a. (3, 4, 5, 20, 5|. b. |3, 5, 20, 4, 5]
C. (3, 5, 20, S] d. Error
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
0
Reason (R): The fixed iterative loop is a looping construct used to repeat the execution
a block of statements for afixed number of times.
XII-COMPUTER SC.-N
4
18. Assertion(A): Every open filc maintains aile-pointer and keeps track of its position afier
every operation.
Rcason (R): Every read and write opcration takes placc at the current position of the
file
pointer.
SECTION-B
19. What willbe the flow of execution of the following code? 2
I #tunction definition
2 def Increment(X):
3
3 X += 1 4,5. 6,2
4 X=3
5 print(X)
6 Increment(X)
7 print(X)
20. Rewrite the following code in Python after removing all syntax error(s). Underline each
correction done in the code. 2
else:
OR
5 XII-COMPUTER SC.-M
Write afunction Calci(x.y) that tukes two numbers as arguments from user andperforms
addition, multiplication and division on them. The function will have only one returm
statement and result will be displaycd in the main program. For example,
Ifx -42 and y 21, then the outpul will be
Addition: 63
Multiplication: 882
Division: 2.0
Process (b)
print (a)
23.
wnat is the difference between a local
suitable Python code to illustrate both?
variable and a global variable? Also give a
OR
6
XII-COMPUTER SC
Predict the output for the following code:
def add(x,y,z):
print(xtyt2)
def mult(x.y,z): /
retun (*y*z)
a add(6.16,26)
b= mult(2,3,6)
print(a,b)
25. Differentiate between break and continue statements with the help of an cxample. 2
SECTION-C
26. A School has created a dictionary containing top players and their runs as key value pairs
of cricket team. Write a program, with separate user defincd functions to perforrm the
following operations: 3
1. Push the name of the players (keys) of the dictionary into a stack, where the
corresponding runs (valuc) is grcater than 49.
2. Pop and Display the content of the stack.
For example,
If dictionary has the following values:
Data = ('Rohan': 40, 'Rihaan' :55, "Tejas' : 80,'Ajay':90}
The output should be:
Ajay
Tejas
Rihaan
27. What is the pickling and unpickling process? What is the nced of pickling process?
b What is the significance of newline " argument in file open (0 function? 3
XI-COMPUTER SC-M
28. Write a function FileRcad() in Python to read a text file, "Myfile.txt", and display words
having length less than 4 characters.
OR
Wrile a functionCOPYO) in Python to read lines from atext file 'Story.txt' and write the
lines starting with letter T" in another file 'Result.txt'.
29. What are Exceptions? How can we handle the exceptions in Python? Explain wth3
suitableexample.
3
30. Write the statements to pertorm the following operations in Python:
Display the words in a string Sin form of a list.
b. To delete an clement from a list L.
3
Todelete an clement Delhi: 75° from dictionary D.
SECTION-D
31. Write a program in Python to get student details (Rollno, Name and marks) for multiple
students trom the user and crcate a CSV file by writing all the student details in one go.4
Also read and display the data of CSV file.
4
32. a. Explain default and keyword arguments with suitalble examples.
b. Write a program in Python, with separate user defined functions to perform the
following operations on Stack 'city'.
Push the pin code and name of the city in the stack 'city'.
Displaythe latest addedelement in the stack 'city'.
SECTION-E
33. Arun is learning to work with Binary files in Python using a process known as
pickling/unpickling. His teacher has given him the following incomplete code, which is
creating a binary file namely Mydata. dat and then opens, reads and displays the conten
of this created file.
# Statement 1
Slist -[]
for k in range (10):
Slist.append(k*k)
F #Statement 2
#Statement 3
F.closc()
#Statement 4
Data = #Statement 5
F.closc()
print(" [Data from file:", Data)
"Hclp himcompletc the code as per instructions below:
XIL-COMPUTER SC
Complete Statement l so that the required Python library becomes available to the
program.
b Complete Statement 2so that the binary file is opened for writing.
C Complete Statement 3 so that the list Slist, created in the code is written in the
open file.
OR
Ariba has been given following incomplete coue, which takes a student's details (rollno,
name and marks) and writes into a binary file Stud.dat using pickling.
mport pickle
RNo = int(input("Enter Roll no: ")
SName = input("Enter Name: ")
SMarks = float(input("Enter marks: ")
Stud = (Rollno': RNo, Name':SName, Marks':SMarks}
with as F: #Statement 1
#Statement 2
as F1 #Statement 3
#Statement 4
print (data)
if data['Marks'] >=85:
print(Eligible for merit')
else:
9
XII-COMPUTER SC.-M
Cunplew Statenent »that the entioned hinary file is opened for uriting
Complete Statement 2 )that the diaimary Sud' comtents are written on the file
pened in stepla).
Cannplete Statement 3 o that the earlier cTeatsd binary file is opened for reading in
a file objest FI using awith staterent.
mmplee Stalernent 4 o that data frorn file object Fi are read into a dictionary
iamed data.
After completin of the ode, what output willbe produced ifthefollowing daails
are inpt: 3
Enter Marks: 9%
They decided to do everything together, wo the lions couldn't attack therm for food.
Onc day, fivecuws fouyht and cachone startcd to cat yrassin a different place.
he lions decidel sie the opportunity and killed them one by one.
Then the output should be,
They decided o cdo everything toyether, o the lions couldn't attack them for food.
Oncday, five cnws fought and cach one started to cat grass in a different place.
The lions decided 9 eize the opportunity and killed then one by onc.
OR
XI1COMPUTER SC
Can afunction return multiple values? If yes then explain with suitable example.
ABinary file Book.dat has structure [BookNo, BookName, Author].
data for a record and add to
Writc a user defined function FileData) to input
book.dat.
accepts the AuthorName as
2. Write a function CountData(Author) in Python which in
by the given author are stored
parameter and count and return number of books
the binary file Book.dat.
learn Python alsO as it will be helpful
35. Diksha is a student of non-IT stream. She wants to
has assigned her an assignment to
to her in her field. While learning Python, her teacher
complete an incomplete program given below.
(people.csv) that stores tab separated fields
The program intends to print from a csv file
as:
Lname Contact
Empld Fname
Jain 423578901
1001 Vihan
Kishan 435211899
1002 Noor
Jamil 426289736
1003 Harish
434124162
1004 Kulwant Singh
Diksha is as follows:
The incomplete code given to
#Statement 1
import csv
)as F: #Statement 2
with open (
data = CSV. (F,delimiter =\t') #Statement 3
#Statement 4
for J in
#Statement 5
print (
given code so that given csv file is opened in read
a. Complete the Statement 2 of the
mode for processing.
tab separated csv file is read into F object.
b. Complete Statemcnt 3 so that the XII-COMPUTER SC.-M
C. Complete the code of Statement 4 and 5 so that the records from the open csv file
are printed line by line.
d. Write code to Modify the code of Statement 4 and 5 so that only the fourth field
(contact) from cach record gets printed.
e. Write the output obtained by running the code of Statement 4 and 5 after
modification.