12 CS Preterm Answerkeys

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

DELHI PUBLIC SCHOOL

----------BILASPUR----------
PRE-TERM-I (2021-22)
NAME OF THE STUDENT-________________________________________ADM NO.___________________R.No___________________
DATE: 20TH NOVEMBER, 2021
SUBJECT: COMPUTER SCIENCE(083) MAXIMUM MARKS= 35
CLASS: XII SEC-A TIME= 90 MINUTES

Instructions-
 The question paper is divided into 3 Sections - A, B and C
 Section A, consist of 25 Questions (1-25). Attempt any 20 questions.
 Section B, consist of 24 Questions (26-49). Attempt any 20 questions.
 Section C, consist of 6 case study-based Questions (50-55). Attempt any 5 questions
 Please check that this question paper contains 55 questions and 08 printed pages.
 All questions carry equal mark.

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 is from the following is a type of parameter which can be omitted during function call?
A. Positional B. Keyword C. Default D. None
2. The second parameter in seek() is ____________.
A. file position B. offset C. file pointer D. file name
3. Find the invalid identifier from the following:
a. true B. break C. none D. Pass
4. Consider a declaration T=[‘Prog
ram’,100,99.9].
Which of the following represents the data type of T?
A. Tuple B. Dictionary C. List D. String
5. Given a String Str= “Awakening.
What will be output of print( Str[1:8:3])
A. wkn B. waken C. wknn D. wen
6. What is the data type of (99)?
A. Tuple B. Integer C. Set D. Dictionary
7. What will be value of following expression?
>>> 28 % 2 * 13 / / 4 +1
A. 1 B. 1.5 C. 5 D. 0
8. Which file stores data in human readable characters?
A. Text B. Binary C. Both A and B D. None of these
9. Archit wants to position the file pointer to the beginning of a text file. Identify the Python
statement for the same assuming “F” as file object.
A. pickle.seek(0) B. F.seek(0) C. F.seek(1) D. F.setposition(0)
10. Which method is used to convert string into tuple?
A. string() B. tuple() C. convert() D. change()
11. Which method is used to convert string value returned by input() function to a floating point
value?
A. decimal() B. real() C. float() D. double()
12. Which from the following is used to read entire content of a file as string using file object ‘FILE’
A. FILE.readline() B. FILE.readline() C. FILE.read() D. All
13. What is default EOL character in Python?

Page 1 of 08
A. \t B. \r C. \n D. \v
14. What is a variable defined in top level segment (outside all the functions) referred to as?
A. local variable B. global variable C. static variable D. enclosing variable
15. The readlines() method returns
A. string B. list of integers C. list of lines D. list of characters
16. Which of the following symbol is used in Python for multiple line comments?
A. # B. // C. ** D. “ “ “ ” ” ”
17. What is returned by
import math
>>> abs(math.sqrt(25))?
A. 5 B. -5 C. 5.0 D. error
18. Consider following code and predict the output.
>>> Str= “Number 1 programmer”
>>> print( Str.isalnum())
>>> print( Str.isalpha())
A. True B. True C. False D. False
False True True False
19. Observe following statement:
>>> Str1= “Knowledge”
Which from the following will NOT result in error?
A. print(Str1[10])
B. Str1[2]= ‘r’
C. print(Str1[ : 45])
D. All of the above
20. Which function is used to write a list of string in a text file?

A. writeline() B. write() C. writelines() D. dump()


21. Find possible output at the time of execution of the program from the following code?
import random
A=[12, 13, 14, 15, 16, 17];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (A[K],end= “*”)
A. 17*16*15*
B. 14*15*16*
C. 14*15*16
D. 17*16*15
22. What will be the output of the following code?
Str= “DPS,Bilaspur”
Temp= “”
for i in range(len(Str)):
if i % 2 = = 0:
Temp=Temp+Str[i].upper()
else:
Temp=Temp+Str[i].lower()
print(Temp)
A. DpS,bIlAsPuR B. DpS,BiLaSpUr C. dPs,BiLaSpUr D. DpS,BiLaSpUr
23. What is the output of the program given below:
a=10
def value():
global a
a=20
print(a, end= ‘ ’)
Page 2 of 08
print(a, end= ‘ ’)
value()
print(a, end= ‘ ’)
A. 10 20 20 B. 10 20 10 C. 10 10 10 D. 10 10 20
24. What is the output of following code?
>>> D={“A”:1, “B”:2, “C”:3}
>>> D.keys()
A. {“A”, “B”, “C”}
B. [“A”, “B”, “C”]
C. dict_keys([‘A’, ‘B’, ‘C’])
D. (“A”, “B”, “C”)
25. Which method is used to delete a key and its respective value from a dictionary?
A. del() B. delete() C. pop() D. remove()

Section-B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions
26. Which from the following is a correct method to open a file “D:\Life.txt” for writing data?
A. FP=open(“Life.txt”, “w”)
B. FP=open(“D:\Life.txt”, “w”)
C. FP=open(“D:\\Life.txt”, “w+”)
D. FP=open(“D:\\Life.txt”, “w”)
27. What will be output of following code:
i=34
while i>=5:
if i % 10 = = 0:
break
else:
print(i,end= ‘ ’)
i -=1
A. 34 33 32 31 30
B. 34 33 32 31
C. No output
D. 34 33 32 28.

29. Which of the following properly expresses the precedence of operators (using parentheses) in
the following expression:
6 / 3 > 10 or 2 * 11==11
A. (6/(3>10)) or (2 * (11 = = 11))
B. ( ( 6 / 3) > 10 ) or ((2 * 11) = = 11)
C. (((6/3) >10) or (2*11)) = = 11
D. (6 / 3) > (10 or 2) * 11 = =11
30. What will be output of following code?
L=[“We”, “learn”, “always”]
print( “ ”.join(L))
A. Welearnalways
B. We learn always
C. We
learn
always
D. Error
31. What is the output of following code?
Page 3 of 08
D={‘Apple’:10, ‘Banana’:25, ‘Orange’:15}
Sum=0
for key in D:
if D[key]>10:
Sum=Sum+D[key]
print(“Total= ”,Sum)
A. Total=50 B. Total=25 C. Total=35 D. Total=40
32. Identify output of following code.
L=[32,44,12,56,78,28]
L.insert(3,99)
L.append(100)
L.extend([1,2])
print(L)
A. [32,44,99,12,56,78,28,100,1,2]
B. [32,44,12,99,56,78,28,100,[1,2]]
C. [32,44,12,,99,56,78,28,100,1,2]
D. [32,44,12,99,56,78,28,100,1,2]
33. What will be output of following?
>>> D= { “SNO”: 1 , “CLASS” : 12 , “MARKS” : 100 }
>>> d1=D.copy()
>>> d1[“MARKS”]=99
>>> print(D)
A. {“SNO”: 1 , “CLASS” : 12 , “MARKS”:99}
B. {“SNO”:1,“CLASS”:12,“MARKS”:100 }
C. {“SNO”: 1 , “CLASS” : 12 , “MARKS”:[99,100]}
D. Error
34. What will be output of code given below?
>>>STR= “VIBGYOR”
>>>Colour= list(STR)
>>> del Colour[4]
>>>Colour.remove(“B”)
>>>Colour.pop(3)
>>>print(Colour)
A. [“V”, “I”, “G”, “R”]
B. [“V”, “I”, “G”, “O”, “R”]
C. ‘VIGR’
D. [“V”, “I”, “G”, “R”]
35. Consider the content of text file “Info.txt” as:
The strength of the class is full.
Find the output of the following code –
Fobj = open("Info.txt", "r")
s=Fobj.read(12)
t= Fobj.read()
print(t)
Fobj.close()
A. The strength of the class is full.
B. The strength
C. No output
D. of the class is full.
36. What will be the output of the following code if content of the file “Passion.txt” is –
Passion is energy.
It is the power,
that comes from
Page 4 of 08
focusing on
What excites you

F=open(“Passion.txt”)
Lines=F.readlines()
print(len(Lines[-1]))
A. 19 B. 16 C. 10 D. Error
37. What will be the output of the following code if content of the file “Strength.txt” is –
One must not push your weaknesses, play with your strength
def test():
File=open(“Strength.txt”, “r”)
Count=0
Str=File.read()
L=Str.split()
for w in L:
if w[0] = = ‘p’:
Count += 1
print(Count)
File.close()
A. 0 B. 3 C. 2 D. No output
38 Assume the content of the text file “Compassiom.txt”
If your compassion
does not include
yourself, It is
incomplete
What will be data type of variable “Rec”.
f1=open(“Compassion.txt”)
Rec=f1.readline()
f1.close()
A. String B. List C. Tuple D. Both a and B
39. Identify the output of following code:
L= [4,2,3,1,6,8,9,11]
L2=L[-3:-7:-2]
print(L2)
A. [8,1,2] B. [8,1] C. [1,8] D. [2,1,8]
40. Which from the following can be used to read the first line of a text file “Test.txt” using
using file handle F.
F=open(“Test.txt”)
A. F.read(1) B. F.readline(1) C. F.readline() D. F.readlines()
41. Identify the output of the following Python statements.
Sum=0
for x in range(4,40,5):
if x % 2 ==0:
Sum=Sum+x
else:
Sum=Sum-x
print(Sum)
A. 40 B. 50 C. -10 D. -20
42. Identify the output of the following Python statements.
T=20
while T<10:
T=T-4
print(T,end= ‘ ’)
Page 5 of 08
A. 20 16 12 8 4 0
B. 20 16 12
C. 16 12
D. No output
43. Identify the output of the following Python statements.
L=[ [1,2,3], “Nesting”, [2.75,12.0], “List”]
T=L[1][1] * 3
print(T)
A. Nesting B. [1,2,3] C. e D. eee
44. David wants to write a List L1 = [9,2,13,11,5] on a binary file Try.bin. Consider the following
code written by him.
import pickle
L1 = [9,2,13,11,5]
File1 = open("Try.bin",'______') #Statement 1
pickle.dump(L1,File1)
File1.close()
Identify missing file mode in Statement 1
A. w B. w+ C. w+B D. wb
45. A binary file Item.dat has following data

ItemCode ItemDescrip Quantity Price


100 Chair 50 3500
101 Table 4 8000
102 Fan 35 5000
103 Clock 75 6000

def Check():
FOb=open("Item.dat","rb")
total_price=0
try:
while True:
Rec=pickle.load(FOb)
if Rec[2]<50:
__________ #Statement1
total_price=total_price+Rec[3]
except:
FOb.close()
print(total_price)
When the above mentioned function, Check() is executed, the output displayed is 6000.Write
appropriate jump statement for Statement1 to obtain the above output.
A. break B. continue C. goto D. return
46. What will be the data type of variable Final_Value?
def Larger(Value1, Value2):
if Value1>Value2:
return Value1
elif Value2>Value1:
return Value2
elif Value1= = Value2
return Value1, Value2
Final_Value = Larger(50,50)
A. List B. Integer C. tuple D. None of the above
Page 6 of 08
47. Observe following code:
def param(num1, num2,num3=20):
num1*=2
num2 = num3 / 2
return num1+num2
Which function call statement is incorrect?
A. param(num2 = 4, num1 = 6)
B. param(num2 = 9)
C. param(4,6,8)
D. param(num1=8, num2=10,num3=10)
48. What could be possible output of the following code?
import random
Colours=["Red","Orange","Yellow","Pink", “Green”]
for C in range(len(Colours)):
Temp = random.randint(1,3)
print(Colours[Temp],end="&")
A. Red&Red$Green&Orange&Pink
B. Orange&Red&Yellow&Pink&
C. Orange&Pink&Yellow&
D.Orange&Green&Yellow&Pink&
49. What will be output of following code?
def StrMix(s):
Temp= ‘ ’
Count=0
for i in s:
if Count%2 = = 0:
Temp=Temp+Str(Count)
if Count%3 = = 0:
Temp=Temp+i.upper()
else:
Temp=Temp+ “*”
Count +=1
print(Temp[3:7])
s1= “StuDENT”
StrMix(s1)
A. 1S2U B. 2*D4 C. 2D*3 D. 2*d4

Section-C
Case Study based Questions
This section consists of 6 Questions (50 -55) Attempt any 5 questions.
Shubha is learning to write Python program and wanting to perform CSV file operations with
the help of two user defined functions:
A. CSVOpen() : To create a CSV file called Customer.csv in append mode containing information
of customer – CustId, CustName, Age.
B. CSVRead() : To display the records from CSV file Customer.csv where the field CustName
starts with letter ‘A’.
She has succeeded in writing partial code and has missed out certain statements, so help her in
completing the missing statements marked as statement 1 to 6.

Page 7 of 08
import ___________ #Statement-1
def CSVOpen():
with open(“Customer.csv”,_________,newline= ‘ ’) as F1: #Statement-2
cw=____________ #Statement-3
cw.__________([101, ‘ Amit Verma’,30]) #Statement-4

def CSVRead():
try:
with open(“Customer.csv”, “r”) as F2:
cr=____________ #Statement-5
for i in cr:
if __________: #Statement-6
print(i)
except:
print(“No such file exists”)
#Main Program
CSVOpen()
CSVRead()

50. Which module should be imported in Statement-1.


A-pickle B- csv C- file D- text
51. Which file mode to be passed to append data in file in Statement-2.
A. w+ B. w C- wb D. a
52. What should be written in Statement-3 to create a csv writer object .
A. csv.write(F1) B. csv.writer(F1) C. F1.writer(csv) D. csv.writer()
53. Which function to be used in Statement-4 to append the details of new customer in csv file.
A. writerow() B. writeline() C. write() D. writer()
54. Which statement should be used to read a csv file in Statement-5?
A. csv.reader(F2) B. csv.read(F2) C. csv.reader() D. F2.reader(cr)
55. Identify Statement-6 to check the field CustName starting with letter ‘A’.
A. i[1][1]= = ‘A’
B. i[1][0]= = ‘A’
C. i[0][1]= = ‘A’
D. i[0][0] = = ‘A’

==XXX==

Page 8 of 08

You might also like