Professional Documents
Culture Documents
CLASS XII
COMPUTER SCIENCE (083)
TERM I
Maximum Marks: 35 Time Allowed: 90 Minutes
General Instructions:
1. The question paper is divided into 3 Sections – A, B and C.
2. Section A consists of 25 Questions (1-25). Attempt any 20 questions.
3. Section B consists of 24 Questions (26-49). Attempt any 20 questions.
4. Section C consists of 6 case study based questions (50-55). Attempt any 5 questions.
5. All questions carry equal marks.
Section A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Which statement consists of a logical operator?
(i) a+b**c (ii) a >b:
(iii) a and b not c (iv) 2 in a
2. Given a tuple A = (10,12,14,16,18)
Identify the statement from the list below that will add 17 at the end of the existing elements.
(i) A += (17,) (ii) A = (17,)
(iii) A = A+17 (iv) A += 17
3. Given a tuple T1=(4,3,7,9,7,6,5)
What will be the output of the following code?
print(T1[-7],T1[-3]*3)
(i) 4, 7 7 7 (ii) 4 21
(iii) -5 -7 (iv) 4 –21
4. Which of the following file open modes does not create a new file when the specified file has not yet
been created?
(i) a (ii) w+
(iii) ab+ (iv) r
5. Consider a code:
f=open(“song.txt”,’r’)
a=f.________
print(type(a))
Output: <class 'list'>
Fill in the blanks with the appropriate function that will produce the output shown above.
(i) read() (ii) readlines()
Sample Question Paper 2
b=a
a=b+100
‘’’Here the value of b is now 300 and the value of a is the value of b
increased by 100’’’ #Statement 3
print(a,b)
# Printing the value of a and b #Statement 4
(i) Statement 1 (ii) Statement 2
(iii) Statement 3 (iv) Statement 4
A.3
24. Consider the statements given below:
import pickle
Tup1=(‘Pen’,’Pencil’,’Eraser’,’Notebook’)
with open(‘Mybag.dat’, ‘wb’) as binfile:
--------------------- #Statement1
Identify the missing code in Statement 1 that will write data from a list on the binary file.
(i) pickle.load(mybinfile, Tup1)
(ii) pickle.dump(mybinfile, Tup1)
(iii) pickle.dump(Tup1, binfile)
(iv) pickle.load(Tup1, binfile)
25. Identify the correct statement.
(i) List can be used as keys of dictionary.
(ii) Tuples can be used as keys of dictionary, if they contain only strings, numbers or tuples.
(iii) Lists, like strings are immutable.
(iv) Performing list(dict) on a dictionary returns a list of all the values used in the dictionary.
Section B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. Identify the incorrect statement regarding a tuple tup1.
tup1 =(1,2,3,4,5,6)
(i) len(tup1) (ii) sorted(tup1)
(iii) 4 in tup1 (iv) Tup1+(10)
27. Consider a file “online.txt”
With educational institutes closed due to the COVID-19 pandemic, the government
has been encouraging online education to achieve academic continuity.
Online education allows for learning something beyond the norm.
What will be the output of the following code?
fileobj=open('online.txt','r')
count = 0
l=fileobj.readline()
for i in l:
if 'o' in i:
count=count+1
print(count)
fileobj.close()
(i) 10 (ii) 8
Computer Science with Python–XII
(iii) 9 (iv) 20
28. Identify the output of the following Python statements.
L1=[6,4,2,9,7]
L1[3:]= “100”
(i) [6,4,2,9,7,100] (ii) [6,4,2,100]
(iii) [6,4,2,1,0,0] (iv) [6,4,2, ‘1’,’0’,’0’]
A.4
29. Identify the output of the following Python statements.
x=1
while x<5:
if x%3==0:
print(x*2,end='')
else:
print(x,end='')
x=x+1
(i) 1234 (ii) 1264
(iii) 2364 (iv) 3364
30. Identify the output of the following Python statements.
for i in range(0,10,2):
if i%2==0:
a=i**2
print(a,end='#')
(i) 2#4#6#8#10# (ii) 0#4#16#36#64
(iii) 1#2#3#4#5# (iv) 0#1#2#3#4#5
31. Write the output of the following Python statements:
L1 = [12,32,42,34,54,65]
L2=[87,98,67,90]
L2.pop(1)
L1.extend(L2)
L1.insert(5,100)
print(max(L1[2:9:2]))
(i) 100 (ii) 42
(iii) 87 (iv) 67
32. What will be the contents of the ‘mylist.dat’ file after executing the following code?
import pickle
lst1,lst2=[80,20,31,92,67,81,63][]
for i in lst1:
if(i%2==0 and i%5==0):
lst2.append(i)
f=open(“mylist.dat”,’wb’)
data=pickle.dump(lst2,f)
f.close()
(i) 31 (ii) 80 (iii) 67 (iv) 63
92 20 97 20
33. Consider a CSV file and a code:
Sample Question Paper 2
import csv
with open('myfile.csv','r') as csv_file:
reader=csv.reader(csv_file)
rows=[]
value=0
for i in reader:
if ____________________: #Statement1
continue A.5
rows.append(i)
value=len(list(reader))
print(value)
Identify the suitable code in line marked as Statement1 that will exclude the header and count exact
number of records.
(i) reader.line_num==0
(ii) csv_file.line_num==1
(iii) reader.line_num==0
(iv) reader.exclude_header
34. Consider a function declaration
def Product(a,b):
return a*b
Product(10,12)
Which statement is correct regarding actual argument and formal argument?
(i) Formal argument: a,b and Actual argument: 10,12
(ii) Formal argument 10,12 and Formal argument: a,b
(iii) Both are actual arguments
(iv) Formal argument: a, 10 and actual argument: b, 12
35. Evaluate the following expression and identify the correct answer:
import math
a= math.pow(3,3)+round(48.7) – math.floor(4.09)
(i) 80.0 (ii) 72.0
(iii) 70.0 (iv) 60.0
36. What will be the output of the following code?
t=(1,2,3,4,5,6)
def add(A):
A[0]=A[0]**2
A[1]+=5
return A
b=add(t)
print(b)
(i) (1,7,3,4,5,6) (ii) (1,1,12,3,4,5,6)
(iii) (1,7,5,6,7,8) (iv) Error
37. What will be the output of the following code?
import math
def display(x):
a= sqrt(x)
print(a)
i = 144
display(i)
Computer Science with Python–XII
A.7
43. Suppose the content of ‘Python.txt’ is:
f.close()
(i) 14 (ii) 11
(iii) 10 (iv) 5
46. Consider the content of ‘rhyme.txt’ file:
A.8
What will be the output of the following code?
fileobj=open(‘rhyme.txt','r')
count = 0
l=fileobj.readlines()
for i in l:
if(i[0]=='H'or i[0]==’T’):
count=count+1
print(count)
fileobj.close()
(i) 4 (ii) 2
(iii) 3 (iv) 1
47. Identify the correct statement regarding relative path of a file.
(i) The relative paths are from the root (top) level of the directory structure.
(ii) The relative path includes only the file name if the file is stored in root directory.
(iii) The relative paths are relative to current working directory.
(iv) If the file is in current working directory, then it is denoted with two dots(..) in the file path.
48. When we open a file using this method, we ensure that all of the resources assigned to the file objects
are automatically deallocated when we stop using the file. Identify the method in the above lines.
(i) close() (ii) open()
(iii) with open() (iv) open with()
49. What will be the output of the following code snippet?
Tup1=(10,20,(7,8,9),50)
t=list(Tup1)
print(t)
print(max(t[2]))
(i) [10, 20, (7, 8, 9), 50] (ii) [[10, 20, [7, 8, 9], 50]
9 50
(iii) [10, 20, 7, 8, 9, 50] (iv) ([10, 20, 50])
50 50
Section C
Case Study Based Questions
This section consists of 6 Questions (50 to 55). Attempt any 5 questions.
The owners of the ‘Foodmill’ store wish to generate a bill for each transaction using a binary file. In
order to do this, they have recruited a friend who is learning Python. The friend has made a file called
‘foodmill.dat’ that contains information like Itemno, Item Name, Qty and Price in order to compute Total
Amount, but is having problems finishing it. Assist the friend in finishing the code.
Incomplete Code:
import ________ #Statement 1
File = _____('foodmill.dat','_____') #Statement 2
ch='y'
while True:
Itemno = input("Enter Item No:")
Product = input("Enter Product Name:")
Sample Question Paper 2
A.10
ANSWERS (SAMPLE QUESTION PAPER 2)
1. (iii) a and b not c 2. (i) A += (17,) 3. (ii) 4 21 4. (iv) r 5. (ii) readlines()
6. (i) Generates an error : x must be string 7. (iii) Both (i) and (ii) 8. (iii) * 9. (iv) int
10. (iii) 4 11. (i) Text file 12. (iv) seek(50,0) 13. (iii) pickle 14. (ii) slowly but steadily
15. (iv) The lifetime of the local variable is the entire program run. 16. (ii) def Tot_Marks (T1 = x, T2 = y, Total = z):
17. (ii) Count_Total(‘Shirt’, Cost = 1500, Qty =2, Disc =0.30) 18. (iii) flush()
19. (ii) Comma is used to separate the values. 20. (ii) Binary file 21. (ii) dump(), load()
22. (iii) p q r = 20,30,40 23. (ii) Statement 2 24. (iii) pickle.dump(Tup1, binfile)
25. (ii) Tuples can be used as keys of dictionary, if they contain only strings, numbers or tuples.
26. (iv) Tup1+(10) 27. (iii) 9 28. (iv) [6,4,2, ‘1’,’0’,’0’] 29. (ii) 1264 30. (ii) 0#4#16#36#64
31. (iv) 67 32. (ii) 80 33. (i) reader.line_num==0
20
34. (i) Formal argument: a,b and Actual argument: 10,12 35. (ii) 72.0 36. (iv) Error
37. (iii) Error 38. (iii) 8#0#1 39. (iv) [2, 4, 6, 8] 40. (i) rewoPot.rewopmE
41. (i) T-2-e-4-M-6-t-8-i-1-0- 42. (iii) 8 43. (ii) 13 44. (ii) 10
100
45. (i) 14 46. (i) 4 47. (iii) The relative paths are relative to current working directory.
48. (iii) with open() 49. (i) [10, 20, (7, 8, 9), 50] 50. (i) pickle 51. (ii) open ‘wb’
9
52. (iii) dump(records,file) 53. (iv) pickle.load(f) 54. (iii) total_Amt+=R[4]55. (ii) except
A.11