0% found this document useful (0 votes)
193 views4 pages

KV No 1, Afs, Agra: Section - A

The document is a sample exam paper for Class XII Computer Science. It contains 3 sections - Section A with 6 multiple choice questions, Section B with 4 short answer questions and Section C with 5 long answer questions. The questions test concepts in Python programming like importing modules, working with CSV files, functions, data structures like stacks and lists, file handling and more.

Uploaded by

Captain America
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
193 views4 pages

KV No 1, Afs, Agra: Section - A

The document is a sample exam paper for Class XII Computer Science. It contains 3 sections - Section A with 6 multiple choice questions, Section B with 4 short answer questions and Section C with 5 long answer questions. The questions test concepts in Python programming like importing modules, working with CSV files, functions, data structures like stacks and lists, file handling and more.

Uploaded by

Captain America
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

केन्द्रीय विद्यालय क्रमाांक 1, िायस

ु ेना स्थल, आगरा /KV No 1, AFS, AGRA


PERIODIC TEST -1 EXAMINATION (SESSION 2022 - 23)
Class: XII Time: 90 Minutes
Subject: (083) COMPUTER SCIENCE MM: 40
General Instructions:
- Paper is divided into three sections
- Section A - Competency Based Questions – 12 Marks
- Section B - MCQ, Case based Questions, Source based Integrated Questions – 8 Marks
- Section C - Short Answer/Long Answer Questions – 20 Marks

SECTION - A
Neha is making software on “Items & their prices” in which various records are to be
stored/retrieved in STORE.CSV data file. It consists some records (Item & Price).
She has written the following code in python. As a programmer, you have to help her to
successfully execute the program.

import ___________ # Statement-1


def AddItem(Item, Price) ___ # Statement-2
f=open(“STORE.CSV”, ___ ) # Statement-3
fw=csv.writer(f)
fw.writerow([Item, Price])
____________ # Statement-4

def ShowRecord():
with open(“STORE.CSV”,”r”) as NI:
NewItem=csv._______ (NI) # Statement-5
for rec in NewItem:
print(rec[0], “#”, rec[1])

#main-code
AddItem(“Sugar”, 38.00)
AddItem(“Rice”, 48.50)
ShowRecord() # Statement-6

Q1. Which module should be imported in Statement-1. [1]


A. pickle B. csv C. file D. text
Q2. Which file mode to be passed to add new record in Statement-3. [1]
A. w+ B. w C. wb D. a
Q3. What should be written in Statement-4 to close the file? [1]
A. close() B. fw.close() C. f.close() D. csv.close()
Q4. Which function to be used in Statement-5 to read the data from a csv file.[1]
A. read() B. readline() C. readlines() D. reader()
Q5. Output after executing Statement-6 will be [1]
A. (“Sugar”, “38.0”) B. Sugar 38.0
(“Rice”, “48.50”) Rice 48.0
C. Sugar, 38.0 D. Sugar # 38.0
Rice, 48.50 Rice # 48.50
Q6. Write full form of LIFO and name the data structure which uses this concept. [1]
Q7. Consider the following code: [2]
import random as r
def myData():
for I in range(4):
print(100 + r.randint(5,10), end=’ ‘)

Find the suggested output option(s) (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 102 105 104 105 (ii) 110 103 104 105
(iii) 105 107 105 110 (iv) 110 105 105 110

Q8. Find and write the output of the following Python code: [2]
def findOutput():
data=["P",20,"R",10,"S",30]
times, add = 0, 0
alpha=""
for c in range(1, 6, 2):
times = times + c
alpha = alpha + data [c-1] + "$"
add = add + data[c]
print (times, add, alpha)
findOutput()
Q9. Write python code to print just the last line of a text file “data.txt” [2]

SECTION – B
Q10. Find the output: [1]
def fun1(t):
return max(t)
#main-code
a=('Amit', 'Sumit','ashish','Sumanta')
print(fun1(a))

A) Sumit B) ashish C) Sumanta D) Amit


Q11. Rishang developed a python code to update a binary file “stock.dat”, He opened file
using command with open(“Stock.dat”, “rb+”) as f:
later he realized that he forgot to close the file in program, what can be the
consequences: [1]
A. file will be closed automatically B. data written file will get deleted
C. file will not open in next run D. unpredictable
Q12. Find the output of the following code: [1]
def short (lst, n):
for i in range (0,n):
if len(lst[i])>4:
lst[i] = lst[i][0 : 4]
else:
lst[i]=lst[i]
sub=['IP', 'HINDI', 'CS', 'Mathematics', 'Chemistry', 'Physics']
short(sub,6)
for i in sub:
print(i, end=',')
A. IP, HINDI, CS, Mathe, Chemi, Physi, B. IP, HIND, CS, Math, Chem, Phys,
C. IP, HINDI, CS, Mathematics, Chemistry, Physics D. IP, HIN, CS, Mat, Che, Phy,
Q13. Choose the correct option: [1]
Statement1: Local Variables are accessible only within a function or block in which
it is declared.
Statement2: Global variables are accessible only within the function in which they
are defined.
A. Stmt 1 is correct but Stmt 2 is incorrect B. Stmt 2 is correct but Stmt 1 is incorrect
C. Both Statements are Correct D. Both Statements are incorrect

Q14. This method is used to unpickling data from a binary file: [1]
A. dump B. unpickle C. load D. seek
Q15. Find the output of the following code: [1]
def test(n):
D1 = {"cat":17, "dog":6, "bear":23}
return n in D1
print(test(23))
A. False B. True C. None D. Error
Q16. What are the technical names of insertion and deletion in a stack? [1]
Q17. Find the output of the following: [1]
def func(message, times=3):
print(message*times)
#main-code
func(‘Python’)
func(‘Easy’* 3)
SECTION – C

Q18. The following function is created for you: [2]


def findInterest(prin, rate=5, time=2):
SI=(prin * rate * time)/100
return SI
Find the output of the following code:
(a) print(findInterest(1000, 10, 5)) (b) print(findInterest(2000, 3))
(c) print(findInterest(5000)) (d) print(findInterest())
Q19. Write definition of a function HowMany(ID, VALUE) to count and display number
of times the VALUE is present in the list ID. [2]
For example, if the ID contains
[115, 25, 65, 59, 74, 25, 110, 250] and the VALUE contains 25, the function should
print: 25 found 2 times.
Q20. What are the advantages of saving a file in (i) text form (ii) csv file? [2]
Q21. Identify the error in the following code and re-write the correct code. [2]
f=open(‘//tmp//workfile.txt’, ‘r+’)
f.write(‘0123456789abcdef’)
f.write(’04-July-2022’)
f.close()
f.seek(0)
data=f.read(5)
print(data)
Q22. As per Government of India order only age 15 to 18 students are eligible for
vaccine. Write a program to implement a stack from the list of values containing
age of 10 students with separate user defined functions to perform the following.
• push the age of students into stack for those whose age is in between 15 to 18
years (Both values included) [3]
• pop and display the age of students from the stack.
If the list containing following values:
L = [12, 16, 18, 19, 15, 17, 14, 19, 16, 13], then the output of the code should be
16 17 15 18 16
Q23. Write a function which accept a list as parameter and return the list of squares of all
its element as a tuple. Test the same code in main code. [3]
Example, if passed list is [1, 2, 3, 4], then returned tuple will be (1, 4, 9, 16)
Q24. A binary file ‘book.dat’ has structure as [bno, name, author, price]. Write a user
defined function createFile() to input data for a record and add to ‘book.dat’. [3]
Q25. Write a program to count the words “to” and “the” present in a text file “my.txt”.[3]

0-O-o- Best of Luck –o-O-0

You might also like