Gr.12 Computer Science - Unit Test 2 - QP
Gr.12 Computer Science - Unit Test 2 - QP
COMPUTER SCIENCE
Class: XII Duration: 1 ½ hrs.
Date: 20/09/2023 Max Marks: 40
General Instructions:
• All questions are compulsory.
• The question paper has five sections: Section A to E.
• Section A has 6 questions carrying 01 mark each.
• Section B has 4 Very Short Answer type questions carrying 02 marks each.
• Section C has 4 Short Answer type questions carrying 03 marks each.
• Section D has 1 Long Answer type questions carrying 04 marks each.
• Section E has 2 questions carrying 05 marks each.
SECTION –A
1. Choose the output of below code: (1)
if False:
print('Hi')
elif True:
print('Hello')
else:
print('Howdy')
(a) Nothing
(b) Hi
(c) Hello
(d) Howdy
2. Choose the output of below code: (1)
x='Hello world'
print('hello' not in x)
(a) True
(b) False
(c) Error
(d) No of the above
Page 1 of 6
(a) 2 3 4
(b) 9 16 16
(c) 16 4 16
(d) 2 4 9
4. What will be the output of the following code if content of the file “smile.txt” (1)
is –
Smiling is infectious,
You catch it like the flu.
When someone smiled at me today,
I started smiling too.
file=open(“smile.txt”)
contents=file.read()
print(file.read(7))
(a) Smiling
(b) Smilin
(c) ng too.
(d) No output
(a) 1, 2 and 4
(b) 2 & 3
(c) 1 &4
(d) 3 & 4
6. Assertion (A):- Binary files are often more efficient than text files. (1)
Reasoning (R):- Binary files are capable to handle large files and faster I/ O
operations.
Page 2 of 6
SECTION – B
7. Find the output of the following code (2)
msg="Mind@2Work"
n=len(msg)
newmsg=""
for ch in msg:
if ch.islower():
newmsg=newmsg+ch.upper()
elif ch.isupper():
newmsg=newmsg+ch.lower()
elif ch.isdigit():
newmsg=newmsg+str(int(ch)*5)
else:
newmsg=newmsg+'*'
print (newmsg)
8. Rewrite the following code after removing the syntax error(s) if any. Underline (2)
each correction.
def funct(x):
a=a+x
if a%2=0
print (a)
for i in (0:5):
print (i )
a=20
b=5
funct(b)
print(a)
9. Observe below code and find the output(s) not possible from the suggested (2)
Output Options (i) to (iv). Also, write the minimum and maximum values,
which can be assigned to the variable MyNum.
import random
Max=5
MyNum = 20 + random.randint(1,Max)
N=MyNum
while N<=25:
print (N, "*",sep='',end='')
N=N+1
(i) 20*21*22*23*24*25*
(ii) 22*23*24*25*
(iii) 25*
(iv) 21*22*23*24*25
Page 3 of 6
10. Find the output of the following code. (2)
def validate (C,N,divide):
for i in range(0,N):
if i < divide :
C[i]+=i
else:
C[i]*=i
def display (C,N):
for i in range (0,N):
if i % 2 == 0:
print (C[i],'%',end=' ')
else:
print (C[i])
OR
def func(x,y=10):
if x%y==0:
return x+1
else:
return y-1
p=20
q=23
q=func(p,q)
print (p,q)
p=func(q)
print (p,q)
q=func(p)
print (p,q)
SECTION-C
11. Write a Python function to accept 10 integer numbers and display the sum. Use (3)
try/except to catch the exception if floating-point number or any other type of
data is entered.
12. For a given list num=[45,22,14,65,97,72], write a python function to replace all (3)
the integers divisible by 3 with “ppp” and all integers divisible by 5 with “qqq”
and replace all the integers divisible by both 3 and 5 with “pppqqq” and display
the output.
Page 4 of 6
13. Write user defined function in Python to read lines from a text file DIARY.TXT, (3)
and display those lines starting with an alphabet ‘P’.
14. What will be the output of the following python code? Explain the (3)
try/except/finally used in the code.
U=0
V=6
print ("First")
try:
print ('Second')
M=V/U
print ('Third',M)
except ZeroDivisionError :
print (V*2)
print ('Fourth')
else:
print (V*3)
print ('Fifth')
finally:
print (V*4)
print ('Sixth')
SECTION-D
15. In an online lottery system, names having exactly 5 characters are to be (4)
displayed. Preeti has been asked to complete this task. She has created a
function FindNames() in python which read contents from a text file
LOTTERY.TXT, which contains names of participants, and displays those
names, which are having exactly 5 characters. She got confused with few
statements and left it blank. Help her to complete the code.
def FindNames(_______________):
c=0
file=open(filename)
line = file.read()
word = _____
for c in word:
if _____:
print(c)
file.close()
FindNames(____________)
Page 5 of 6
SECTION-E
16. Design a function in python that retrieves file paths from the "file_paths.txt" (5)
document, where each line is either an absolute or relative file path. Then, copy
all absolute paths to a file named 'absolute.txt' and relative paths to a separate
file called 'relative.txt'.
17. A pickled file “Games.dat”, contains the records of Players in the below format: (5)
[playerno, player_namedata, rank]
Write user defined functions in Python
(i) to write player data into the file “Games.dat”.
(ii) to read contents of the file “Games.dat” and display the details of
those players whose rank is above 100. Write appropriate statements
to check the EOF condition.
Page 6 of 6