North Cluster Examination 2021-2022 Class: Xii Subject: Computer Science

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

NORTH CLUSTER EXAMINATION 2021-2022

CLASS : XII
SUBJECT: COMPUTER SCIENCE[083]
Maximum Marks: 35 Time Allowed: 90 Minutes
General 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.
● All questions carry equal marks.
Q.N Section-A
.
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from
this section. Choose the best possible option.
1 What type of error is returned by following statement?
print(int("a"))
a. Syntax error b. ValueError c. TypeError d. None of the above
2 What is the minimum and maximum value of 'A' in the following statement..
import random
A=random.randint(2,30)
print(A)
a.3 and 30 b. 2 and 3 c. 02 and 29 d. 2 and 30
3 Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70) c. [40,60] d. (40,60)
4 Write the value that will be assigned to variable a
A=20*5+3**2%2//5
a. 101 b. 100 c. 1.9 d. none of these
5 Which of the following option is not correct?
a. if we try to read a text file that does not exist, an error occurs.
b. if we try to read a text file that does not exist, the file gets created.
c. if we try to write on a text file that does not exist, no error occurs.
d. if we try to write on a text file that does not exist, the file
gets Created.
6 Which of the following options can be used to read the first line of a text file Myfile.txt?
a. myfile = open('Myfile.txt'); myfile.read()
b. myfile = open('Myfile.txt','r'); myfile.read(n)
c. myfile = open('Myfile.txt'); myfile.readline()
d. myfile = open('Myfile.txt'); myfile.readlines()
7 Assume that the position of the file pointer is at the beginning of 3rd line in a text file.
Which of the following option can be used to read all the remaining lines?
a. myfile.read() b.myfile.read(n) c.myfile.readline() d.myfile.readlines()
8 Which of the following statement is incorrect in the context of binary files?
a. Information is stored in the same format in which the information is held in memory.
b. No character translation takes place
c. Every line ends with a new line character
d. pickle module is used for reading and writing
9 Which of the following statements correctly explain the function of seek() method?
(a) tell the current position within the file.
(b) indicate that the next read or write occurs from that position in a file.
(c) determine if you can move the file position or not.
(d) move the current file position to a different location at a defined offset.

10 A text file student.txt is stored in the storage device. Identify the correct option out of
the following options to open the file in read mode.
i. myfile = open('student.txt','rb')
ii. myfile = open('student.txt','w')
iii. myfile = open('student.txt','r')
iv. myfile = open('student.txt')
a. only I b.both i and iv c.both iii and iv d.both i and iii
10 Which of the following statement is true?
a. pickling creates an object from a sequence of bytes
b. pickling is used for object serialization
c. pickling is used for object deserialization
d.pickling is used to manage all types of files in Python

11 Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile


is the file object. What is the default value of reference_point?
a. 0 b.1 c.2 d.3
12 Consider square numbers defined as follows:
compute(1) = 1
compute(N) = compute(N-1) + 2N-1
According to this definition, what is compute (3)?
a)compute(3) = compute(2) +compute(1) c)compute(3) = compute(2) -2*3+1
b)compute(3) = compute(2) + 2*3-1 d)compute(3) = compute(3) +2*3-1
13 Which of the following character acts as default delimiter in a csv file?
a. (colon) : b.(hyphen) - c. (comma) , d. (vertical line) |
14 Syntax for opening Student.csv file in write mode
is myfile = open("Student.csv","w",newline='').
What is the importance of newline=''?
a. A newline gets added to the file
b. Empty string gets appended to the first line.
c. Empty string gets appended to all lines.
d. EOL translation is suppressed

15 Which of the following is not a function / method of csv module in Python?


a. read() b.reader() c.writer() d.writerow()
16 Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable
17 Which of the following statement opens a binary file record.bin in write mode and
writes data from a list lst1 = [1,2,3,4] on the binary file?
a. with open('record.bin','wb') as myfile:
pickle.dump(lst1,myfile)
b. with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c. with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
18

a) 20 24 28 b) 20,24,28 c) (20,24,28) d) Error


19 Which of the following options can be used to read the first line of a text file data.txt?

a. f = open(‘data.txt’); f.read()
b. f = open(‘data.txt’,’r’); f.read(n)
c. myfile = open(‘data.txt’); f.readline()
d. f = open(‘data.txt’); f.readlines()
20 ____________________ module is used for serializing and de-serializing any Python
object structure.

a. pickle b. unpickle c. pandas d. math


21 Which statement will open file “data.txt” in append mode?
a. f = open(“data.txt” , “a”) b. f = Open(“data.txt” , “ab”)
c. f = new(“data.txt” , “a”) d. open(“data.txt” , “a”)
22 Which module to be imported to make the following line functional?
sys.stdout.write("ABC")
a. system b. sys c. stdout d. stdin
23 Which statement will return error?
import pickle
f=open("data.dat",'rb')
d=pickle.load(f)
f.end()
a. Statement 1 b. Statement 2 c. Statement 3 d. Statement 4

24 Write the output of the following.


T = [1,2,3,4]
T1=[5,6,7]
L=T.append(T1)
print(L)
a. None b. [1,2,3,4,[5,6,7]] c. [] d. error
25 Which statement is not correct for the following code?
A = {1 : "One", 2 : "Two", 3 : "Three"}
A[4] = "Four"
a. It will add value at the end of dictionary. b. It will modify value if the key already
exist.
c. It will add value in between of the dictionary. d. None of the above
Section-B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26 Give the output
for i in range(1,10,3):
print(i,sep=”-”,end=”*”)
(a) 1-4-7* (b) 1-4-7-10* (c) 1*4*7* (d) 1*4*7*10

27
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky

Suppose content of ‘Myfile.txt’ is: What will be the output of the following code?

f = open(“Myfile.txt”)
data=f.readline()
data=f.read()
print(data)
f.close()
(a) Twinkle twinkle little star (b) How I wonder what you are
(c) Twinkle twinkle little star (d) How I wonder what you are-
How I wonder what you are Up above the world so high
Like a diamond in the sky

28 How many times does the following while loop get executed?
K=5
L=36
while K<=L:
K+=6
(a) 4 (b) 5 (c) 6. (d) 7
29 Identify the output of the following Python statements.
b = 1
for a in range(1, 10,
2): b += a + 5
print(b)
a. 59 b.51 c.36 d.39
30 What will be displayed after the execution of the following loop?
sum,last=0,10
for C in range(1,last,2):
sum=sum+1
print(sum,C)
(a) 5,10 (b) 4,9 (c) 5,9 (d) 4,10
31 Rahal is trying to read data from a binary file test.bin and store it into List L.
Consider the following code written by him.
import pickle as p
with open(‘test’,’rb’) as f:
#statement 1
Identify the missing code in Statement 1.
(a) f=p.load(L) (b) p=p.load(L) (c) L=p.load(f) (d) f=L.load(p)

32 What will be the output of the following Python code?


def add (num1,
num2): sum =
num1 + num2
sum =
add(50,30)
print(sum)
a. 50 b. 0 c.Null d.None
33 Write a user defined function in Python that displays the number of lines starting with ‘H’
in the file story.txt. Eg: if the file contains:
Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

a. 5 b. 2 c. 4 d.7
34 What will be the output of the following code?

value = 50
def display(N):
global value
value = 35
if N%7==0:
value = value +
N else:
value = value -
N print(value, end="#")
display(20)
print(value)

a. 50#50 b. 50#15 c. 50#30 d. 5#50#


35 What will be the output of the following code?
def my_func(var1=100,
var2=200): var1+=10
var2 = var2 -
30 return
var1+var2
print(my_func(50),my_func())

a. 250 280 b. 230 280 c. 250 75 d. 250 300


36 What will be the output of the following code?
import random
X=[100,75,10,125]
Go=random.randint(0,3)
for i in range(Go):
print(X[i],”$$”,end=’ ‘)
a. 100$$75$$10$$ b.75$$10$$125$$
c. 75$$10$$ d.10$$125$$100
37 Which of the following is not method of dictionary?
a. len() b. pop() c. del() d. update()
38 Find and write the output of the following python code:
Text=”Mind@Work!”
T=” “
C=0
for I in Text:
if not i.isalpha():
T=T+”*”
elif not i.isupper():
T=T+(Text;c+1])
else:
T=T+i.upper()
c=c+1
print(T)
a. Mind@Wrk!* b. Mnd@*Work& c.Mnd@*Wrk!* d. Mind@wrk!&
39 ________ function is required to find the second occurrence of 'a' in "amita"
a. find() b. index() c. repeat() d. pos()
40 Consider the following directory structure.

Suppose root directory (School) and present working directory are the same. What will
be the absolute path of the file Syllabus.jpg?
a. School/syllabus.jpg b. School/Academics/syllabus.jpg
c.School/Academics/../syllabus.jpg d. School/Examination/syllabus.jpg
41 Write a method/function DISPLAYWORDS() in python to read lines from a text file
STORY.TXT, and display those words, which are less than 4 characters.

My first book was Me and My Family. It gave me chance to be Known to the world.

a.11 b. 14 c. 12 d. 10
42

Suppose content of ‘Myfile.txt’ is


What will be the output of the following code?
myfile = open(“Myfile.txt”)
record=myfile.readline()
record =
myfile.readline().split()
print(len(record))
myfile.close()
(a) 4 (b) 7 (c) 11 (d) 10
43 Which of the following options can be used to read the last line of a text file?
a. file=f.readlines() b. file=f.readline(-1)
print(file[-1]) print(file)
c. file=f.read() d. file=f.read(-1)
print(file[-1]) print(file)
44 In f=open(“abc.txt”,”w”), ‘w’ refers to
(a) file name (b) file object (c) file access mode (d) file pointer

45 When the function ABLINES() is executed, it read contents from a text file
LINES.TXT, to display those lines, which are either starting with an alphabet ‘A’ or
starting with alphabet ‘B’.
def ABLINES():
file=open(‘LINES.TXT’,’r’)
lines = file.readlines()
for w in lines:
if___
print (w)
file.close()
Select the appropriate statement to fill the statement 1.
(i) w[0]= =”A” or w[0]= =”B” (ii) w[0] in [“A”,”B”]
(iii) w[0]= =”A” and w[0]= =”B” (iv) w[0]= =”A”,”B”
(a) (i) and (ii) (b) (ii) and (iv) (c) (i) and (iv) (d) (ii) and (iii)
46 EOL stands for________
a. End of line b.End of list c. end of loop d. none of these

47 Give the output


lt=[1,0,5,8,10,15]
lt2=[[‘one’,’two’,’three’],
[4,5,6]] lt[2]=lt[3]
lt[0]=lt[1]
lt2[-1][0]=lt[2]+3
print(lt2[1])
a) [“two”] (b) [4,5,6] (c) [11,5,6] (d) [“two’,”three”]
48 What will be the output of the following code?
name=”ComputerSciencewithPython”
print(name[3:10])
(a) mputerS (b) puterSc (c) mputerScie (d) puterScien
49 Which command is used to move the file pointer at 5 position in text file.
a. f.tell(5) (b) f.position(5)(c) f.seek(5) (d) f.pointer(5)
Section-C
Case Study based Questions
This section consists of 6 Questions (50 -55) Attempt any 5 questions.
Snigdha is making a software on “Countries & their Capitals” in which various records are to be
stored/retrieved in CAPITAL.CSV data file. It consists some records (Country & Capital). 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 AddNewRec(Country,Capital): # Fn. to add a new record in CSV file
f=open(“CAPITAL.CSV”,_________) # Statement-2
fwriter=csv.__________ # Statement- 6
fwriter.writerow([Country,Capital])
____________ # Statement-3
def ShowRec(): # Fn. to display all records from CSV file
with open(“CAPITAL.CSV”,”r”) as NF:
NewReader=csv.___________(NF) # Statement-4
for rec in NewReader:
print(rec[0], “#”, rec[1])
AddNewRec(“INDIA”, “NEW DELHI”)
AddNewRec(“CHINA”, “BEIJING”)
ShowRec() # Statement-5
f.close()
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 add new record in Statement-2.
(a) w+ (b) w (c) wb (d) a

52 What should be written in Statement-3 to close the file?


(a) close() (b) fwriter.close() (c) f.close() (d) csv.close()

53 Which function to be used in Statement-4 to read the data from a csv file.
(a) read() (b) readline() (c) readlines() (d) reader()

54 The output after executing Statement-5 will be –


(a) (“INDIA”, “NEW DELHI”) (b) INDIA NEW DELHI
(“CHINA”, “BEIJING”) CHINA BEIJING
(c) INDIA, NEW DELHI (d) INDIA # NEW DELHI
CHINA, BEIJING CHINA # BEIJING
55 Choose the function name (with argument) that should be used in the blank space of line
marked as Statement-6.
a) reader(f) b) reader(MyFile) c) writer(f) d) writer(MyFile)

You might also like