INC SR CBSE CBSE BOARD DATE:18-05-2024
TIME: 3 Hrs COMPUTER SCIENCE (083) MAX. MARKS: 70 M
General Instructions:
(i) Please check this question paper contains 35 questions.
(ii) The paper is divided into 5 Sections- A, B, C, D and E.
(iii) Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
(iv) Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
(v) Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
(vi) Section D, consists of 3 questions (31 to 33). Each question carries 5 Marks.
(vii) Section E, consists of 2 questions (34 to 35). Each question carries 4 Marks.
(viii) All programming questions are to be answered using Python Language only.
SECTION :- A
1. Which of the following is not a Tuple in Python ?
(a) (1,2,3) (b) (‘one’,two’,’three’) (c) (10,) (d) (‘one’)
2. What will be output of the following code snippet:
A=[1.2.3.4,5]
print(a[3:0:-1])
3. What is the output of the following Python statement :
print(5+3**2/2)
4. The numbered position of a letter in a string is called ...............
(a) position (b) integer position (c) index (d) location
5. The keys of a dictionary must be of ............... types.
(a) integer (b) mutable (c) immutable (d) all of these
6. What is the output of the below program?
def C2F(c):
return c * 9/5 + 32
print (C2F(100))
print (C2F(0))
a) 212.0 32.0 56 b) 314.0 24.0 c) 567.0 98.0 d) None of the mentioned
7. Variable declared inside functions may have global scope (True/False)
8. Which arguments given below is skipped from function call?
a)Positional b)Default c)Keyword d)named
9. The function pow(x,y,z) is evaluated as:
a) (x**y)**z b) (x**y) / z c) (x**y) % z d) (x**y)*z
10. Ranjani is working on the sports.dat file but she is confused about how to read data from the binary file.
Suggest a suitable line for her to fulfil her wish.
import pickle
def sports_read():
f1 = open("sports.dat","rb")
_______________
print(data)
f1.close()
sports_read()
11. ______ module is used to store data into an python objects with their structure.
a)csv b)pickle c)os d)numpy
12. The _____ file mode is used to handle binary file for reading.
a)rb b)wb c)r+ d)wb+
13. Importing CSV files can be much faster, and it also consumes less memory while comparing with .xls
files(True/False)
14. A ________ parameter is used to quote all fields of csv files.
15. Read following statement about features of CSV file and select which statement is TRUE?
Statement1: Only database can support import/export to CSV format
Statement2: CSV file can be created and edited using any text editor
Statement3: All the columns of CSV file can be separated by comma only
a. Statement 1 and statement 2 b. Statement 2 and statement 3
c. Statement 2 d. Statement 3
16. Csv stands for ___________________________________ .
Q. 17 and 18 are assertion (A) and reasoning (R) based questions. Mark the correct choice as
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true R is false
(d ) A is false but R is true.
17. Assertion. 'Pickling' is the process whereby a Python object hierarchy is converted into a byte-stream.
Reason. Pickling process is used to work with binary files as a binary file works with byte-streams.
18. Assertion. A function is a subprogram.
Reason. A function exists within a program and works within it when called.
SECTION :- B
19. Write the output of the code given below:
my_dict = {"name": "Kuhan",'Door No.': 100}
my_dict["Door No."] = 128
my_dict['address'] = "Karnataka"
print(my_dict.items())
20. Evaluate the following expressions :
a) 8 // 4 + 18 * 6 / 3– 3
b) b) 35/5 or 5.0 + 30/10
21. Find error in the following code(if any) and correct code by-rewriting code and underline the correction:-
x= int(“Enter value of x:”)
for y in range [0,10]:
if x=y
print( x + y)
else:
print( x-y)
22. What is the output of the below program?
def printMax(a, b):
if a > b:
print(a, ‘is maximum’)
elif a == b:
print(a, ‘is equal to’, b)
else:
print(b, ‘is maximum’)
printMax(3, 4)
23. What is exception handling? Name any two exceptions/Errors.
24. Considering the content stored in file “WORLDCUP.txt”, write the output .
India won the cricket world cup of 1983
F= open(“WORLDCUP.txt”)
print(F.read(2))
print(F.read(2))
print(F.read(2))
25. Write the difference between:
(i) Tell() and seek() (ii) load() and dump()
SECTION :- C
26. What is pickle module? Why we use pickle module?
27. What will be displayed by the following code ?
import pickle
Names = ['First', 'second', 'third', 'fourth', 'Fifth']
for i in range(-1, -5, -1):
lst.append(Names[i])
with open('test.dat', 'wb') as fout:
pickle.dump(1st, fout)
with open('test.dat', 'rb') as fin:
nlist = pickle.load(fin)
print(nlist)
28. What is the difference between implicit type conversion and explicit type conversion?
29. Write a function COUNTSIZE( ) in python to read the file “POEM.txt” and display the (length) size of
file.
30. A binary file “salary.DAT” has structure [employee id, employee name, salary]. Write a function countrec() in
Python that would read contents of the file “salary.DAT” and display the details of those employee whose
salary is above 20000.
SECTION :- D
31. What are the different file access modes? Explain.
32. Write one difference between CSV and text files.
Write a program in Python that defines and calls the following user defined functions :
(i) COURIER ADD (): It takes the values from the user and adds the details to a csv file I courier. csv I.
Each record consists of a list with field elements as cid, s_name, Source, destination to store Courier ID,
Sender name, Source and destination address respectively.
(ii) COURIER SEARCH (): Takes the destination as the input and displays ail the courier records going to
that destination.
OR
Why it is important to close a file before exiting?
Write a program in Python that defines and calls the following user defined functions:
(i) Add_Book( ): Takes the details of the books and adds them to a csv file 'Book.csv'. Each record consists
of a list with field elements as book ID, B name and pub to store book ID, book name and publisher
respectively.
(ii) Search_Book( ) : Takes publisher name as input and counts and displays number of books published by
them.
33. Find the output of the following code.
(i) X= “apple,pear,peach,grapefruit”
Y=X.split(‘ , ‘)
for Z in Y:
if Z<’m’:
print(str.lower(Z))
else:
print(str.upper(Z))
(ii) def changeval(m,n):
for i in range(n):
if m[i]%5==0:
m[i]//=5
if m[i]%3==0:
m[i]//=3
L=[25,8,75,12]
Changeval(L,4)
for i in L:
print(i,end=”#”)
SECTION :- E
34. Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid,
ename and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and update the salary. The
updated record is then to be written in the file temp.dat. The records which are not to be updated also have to
be written to the file temp.dat. If the employee id is not found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the requirement given above:
import _______ #Statement 1
def update_data():
rec={}
fin=open("record.dat","rb")
fout=open("_____________") #Statement 2
found=False eid=int(input("Enter employee id to update their salary :: "))
while True:
try:
rec=______________ #Statement 3
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.____________ #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print("The salary of employee id ",eid," has been updated.")
else:
print("No employee with such id is not found")
fin.close()
fout.close()
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2)
(iii) Which statement should Aman fill in Statement 3 to read the data from the binary file, record.dat
(iv) Write the statement to write the updated data in the file, temp.dat?
35. What is the advantage of using a CSV file for permanent storage? Write a program in python that
Defines and calls the following user defined functions:
ADD( ) – to accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list
with field elements as empid, name and salary to store employee id, employee name and employee
Salary respectively.
COUNT( ) – To count the number of records present in the CSV file named ‘record.csv’
**ALL THE BEST**