0% found this document useful (0 votes)
24 views10 pages

ComputerScience Term 1 2021

Uploaded by

28kpclasses
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)
24 views10 pages

ComputerScience Term 1 2021

Uploaded by

28kpclasses
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/ 10

KENDRIYA VIDYALAYA NO.

2 TAMBARAM, CHENNAI
Class: XII Session: 2021-22
Computer Science (Code 083)
Practice Test : Term-1
Maximum Marks: 35 Duration: 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 will be the correct output of the statement :


>>> 4+2**2*10

a. 18 b. 80 c. 44 d. None of the above


2 Consider a declaration T = [‘three’, ‘4’, 5, 6].
Which of the following operation will not result in error?

a. T + 3 b. T * 4 c. max(T) d. print(T[2][0])
3 What will be the output of the following code?

x = ‘abcde’
i = ‘i’
while i in x :
print(i,end=’ ‘)

a. a b c d e b. i i i i i c. i d. None of the above


4 Minimum how many parameters are passed to open( ) function?

a. 0 b. 1 c. 2 d. 3
5 Which statement is used to retrieve the current position within the file?

a. fp.seek( ) b. fp.tell( ) c. fp.loc d. fp.pos


6 The _____________ of a variable is the area of the program where it can be referenced.

a. external b. lifetime c. local d. scope


7 Which is/are the basic I/O connections in file?

a. Standard Input b. Standard Output


c. Standard Error d. All the above
8 Observe the code given below

def DISPLAYWORDS( ):
count=0
file=open(‘STORY.TXT','r')
line = file.read()
word = line.split()
for w in word:
if w[0]=="T" or w[0]=="t":
count=count+1

What would be the value of count if the contents of the file are

“Many of life’s failures are people who did not realize how close they were to success when they
gave up.”

a. 0 b. 2 c. 3 d. 4
9 The output of the given expression is
>>>20 * (20 / 0)
a. NameError b. TypeError c. OverflowError d. ZeroDivisionError
10 Given
employee={'salary':10000,'age':22,'name':'Mahesh'}
employee.pop('age')
print(employee)

What is output?

a. {‘age’:22} b. {'salary': 10000, 'name': 'Mahesh'}


c. {'salary':10000,'age':22,'name':'Mahesh'} d. None of the above
11 t1=(2,3,4,5,6)
print(t1.index(4))
What will be output of the above code?

a. 4 b. 5 c. 6 d. 2
12 What is the significance of the tell() method?
a. used to change the position of the File Handle to a given specific position.
b. used to tell the position of the File Handle.
c. used to seek the name of the File.
d. used to change the access mode of the File.

13 Which function is used to write all the characters?


a. write()
b. writecharacters()
c. writeall()
d. writechar()
14 Observe the following code snippet

file = open(“electricity.txt”,”r”)

try:

……..

except EOFError: # When will this line execute


……..
When will the line underlined execute?

a. When the file is closed.


b. This is a text file.
c. When the file pointer is at the beginning of the file.
d. When the file pointer has reached the end of file.

15 Observe the following code.

def listchange(arr):
l=len(arr)
for a in range(l):
if(arr[a]%2==0):
arr[a]=10
else:
arr[a]=arr[a]*5

What would be the contents of ‘arr’ after execution of the function if the function call is as follows?

listchange([10,20,31,15])

a. [10, 20, 30, 40] b. [10, 10, 155, 75]


c. [10, 100, 10, 75] d. [50, 10, 155, 10]
16 Which of the below is not a type of parameter of a function?

a. Positional Parameters b. Default Parameters


c. Global Parameters d. Keyword Parameters
17 Find and write the output of the following python code:

a=10
def call():
global a
a=15
b=20
call()
print(a)

a. 10 b. 15 c. Insufficient Data d. Syntax Error


18 readline( ) method will return

a. String b. A list of string


c. A tuple of string d. Integer or string based on contents of the file
19 What does the first row of the CSV file normally contain?

a. The source of data b. Notes about the data


c. The author of data d. The column names of data
20 What will be the output of the following Python code?
import sys
sys.stdout.write('Hello\n')
sys.stdout.write('Python\n')

a. Compilation Error b. Exception


c. Hello Python d. Hello
Python
21 When you read csv file using csv.reader() function it returns the values in _______ object.

a. Dictionary b. Tuple c. Nested list d. Reader


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

a=[[]]*3
a[1].append(7)
print(a)

a. [[],[],[]] b. [[],[7],[]] c. [[7],[7],[7]] d. [[],[],[7]]


23 Name the statement that sends back a value from a function
a. print b. input c. return d. None
24 What is the binary file mode associated with “file must exist, otherwise error will be raised and
reading and writing can take place”?
a. wb+ b. w+ c. rb d. rb+
25 What is the output when following statements is executed ?

a=list((45,)*4)
print(a)

a. (45, 45, 45, 45) b. [(45,),(45,),(45,),(45,)]


c. [45, 45, 45, 45] d. Error
Section-B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26 What is the output when we execute tuple(“hello”)?
a. (‘h’, ‘e’, ‘l’, ‘l’, ‘o’) b. (‘hello’) c. (‘hello’,) d. (‘olleh’)
27 What is the output of following code:
list1 = [15, 10, 5, 20, 5]
print(list1.index(5))
a. 0 b. 1 c. 4 d. 2

28 What will be the output?


t=(1,2)
t=t*2
print(t.count(2))

a. 1 b. 2 c. 4 d. None of the above


29 Identify the lines of code having syntax errors.

def chksum(): # Line 1


x=int(input("Enter a number")) # Line 2
if (x%2 == 0): # Line 3
for i in range(2*X): # Line 4
print(i) # Line 5
else: # Line 6
print( "#' ) # Line 7
chkSUM() # Line 8

a. Line 1 b. Line 8 and Line 4 c. Line 8 d. Line 1 and Line 2


30 Suppose content of 'poem.txt' is:
Focus
Set your standards high,
Study hard.
Take your time and focus,
At one thing at a time.
What will be the output of the following code?
f = open("poem.txt", "r")
n1 = 0
for line in f:
n1+=1
print(n1)

a. 18 b. 10 c. 8 d. 5
31 What will be the output of the following code?

i=1
while True:
if i%3 == 0:
continue
i=i+1
print(i)

a. 1 b. 2 c. Error d. 2
2 3 3
Infinite loop after that
32 Rahul is trying to write a tuple t = (10,20,30,40,50) on a binary file notebook.bin. Consider the
following code written by him.
import pickle #statement 1
t = (10,20,30,40,50) #statement 2
myfile = open("notebook.bin",'w') #statement 3
pickle.dump(t, myfile) #statement 4
myfile.close()
Which of the following statement contains an error ?

a. Statement 1 b. Statement 2 c. Statement 3 d. Statement 4


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

def result(num1, num2):


d = num1 % num2
return d
d = result(20,30)
print(d)

a. 0.6 b. 20 c. None d. 0
34 Suppose content of 'book.txt' is:
open a book
and you will find,
people and places of every kind
open a book
and you can be
What will be the output of the following code?
f = open("book.txt", "r")
x = f.readlines()
print(x[-1])
a. open a book b. open a book c. and you can be d. be
and you will find and you can be
people and places of every kind

35 A list is given as Age=[10, 20,30,40,50,60] . What will be displayed as Age[:2] + Age[2:]?

a. [30] b. [10, 20, 30, 40, 50, 60] c. [[10],[20,30,40,50,60]] d. [30,40,50,60]


36 How do you rename a file having file handle ‘fp’? The file named ‘exiting_name’ is to be renewed
to ‘new_file’.

a. fp.name = ‘new_name.txt’ b. os.rename(existing_name, new_name)


c. os.rename(fp, new_name) d. os.set_name(existing_name, new_name)
Observe the following program and answer the questions that follow:
37 import random
X=3
N=random.randint(1,X)
for i in range(N):
print(i,'#',i+1)

Find out, which line of output given below will not be expected from the program?
a. 0#1 b. 1#2 c. 2#3 d. 3#4
Which of the following function header is not correct for function call fun((1,2,3,4))?
38
a. def fun (a=1, b): b. def fun(c, d, a=1, b=1):

c. def fun(d, a=1, b=1, c=2): d. def fun(* agrs) :

39 Write the output of the following code:


def show(s):
l=s.split('a')
for i in l:
if len(i)>5:
print(len(i))
s="Whatever you are, be a good one"
show(s)

a. 7 b. 10 c. 16 d. None of the above


7 14
9
40 Suppose content of 'Myfile.txt' is
Make it work,
make it right,
make it fast.
What will be the output of the following code?
myfile = open("Myfile.txt")
record= myfile.readline().split()
print(len(record))
myfile.close()
a. 3 b. 4 c. 5 d. 6
41 Suppose content of 'myfile.txt' is:
Hello python
Hello world
What will be the output of the following code?
a = open("myfile.txt", "r")
lines = a.readlines()
for line in lines:
x = line.split()
for i in x:
print(i+ " # ", end=" ")
print(" ")
a. Hello python # b. Hello # python
Hello world # Hello # world
c. Hello # python # d. hello#ython#hello#world #
Hello # world #
42 What will be the output of the following Python code:
val="bTeR%h2q8"
S=""
for x in range(len(val)):
if val[x].isdigit():
S=S+str(len(val))
elif val[x].islower():
S=S+val[x].upper()
elif val[x].isupper():
S=S+val[x].lower()
else:
S=S+"@"
print(S)

a. BtEr@H6Q6 b. BTEr@H9q9 c. BtEr@H9Q9 d. BtEr@H7Q8


43 Suppose content of 'book1.txt' is
Be yourself

What will be the output of the following code?


myfile = open("book1.txt")
x = myfile.read()
print(2*len(x))
myfile.close()
a. 16 b. 14 c. 32 d. 22
44 Suppose content of 'book1.txt' is
What goes around comes around

What will be the output of the following code?


myfile = open("book1.txt")
x = myfile.read()
y = x.count('around')
print(y)
myfile.close()
a. 2 b. 3 c. 6 d. 5
45 Write the output of the following code:
x = 10
def localvar():
global x
x+=5
print(x, end=' ')
print(x+5, end=' ')
localvar()
print(x, end=' ')
a. 10 15 15
b. 10 10 10
c. 15 15 15
d. 10 15 20
46 Suppose content of 'book1.txt' is
Life is beautiful

What will be the output of the following code?


f = open("book1.txt")
print(f.tell(), end=" ")
f.read(5)
print(f.tell(), end=" ")
f.read()
print(f.tell(), end=" ")
f.close()
a. 0 3 16 b.1 4 17 c. 0 5 12 d. 0 5 17
47 Assume the content of text file, 'fly.txt' is:

1234
2345
3456
4567

What will be the data type of record?


f = open("fly.txt")
record = f.read()
f.close()
a. list b. tuple c. dictionary d. string
48 Suppose content of 'Myfile.txt' is

Watch your thoughts;


they become words.
Watch your words; they
become actions. Watch
your actions; they
become habits. Watch
your habits; they
become character.
Watch your character; it
becomes your destiny.

What will be the output of the following code?


f = open("Myfile.txt")
count = 10
data = f.readlines()
for line in data:
if line[0] == ‘W':
count -= 1
print(count)
f.close()

a. 2 b. 3 c. 4 d. 7
49 What will be the output of the following code:
tup = (1,2,[1,2],[3, 9], 6)
tup[3][1]= 4
tup[2][0]+= tup[2][0]
print(tup)
a. (1, 2, [2, 2], [3, 4], 6) b. (1, 2, (2, 2), (3, 4), 6)
c. (1, 2, [1, 4], [3, 4], 6) d. Error
Section-C
Case Study based Questions
This section consists of 6 Questions (50 -55) Attempt any 5 questions.
Chunky is participating in a CodeChef programming contest. There he has been assigned an
incomplete python code (shown below) to create a CSV File 'Employee.csv' and display the file
content (as shown below). Help him in completing the code.

CSV File
empid, name, city
e1, Rekha, Jaipur
e2, Rohini, Udaipur

Incomplete Code
import____________ #Statement-1
f = open(____________, __________) #Statement-2
fobj = csv._________ #Statement-3
fobj.writerow(["empid","name", "city"])
fobj.writerow(["e1", "Rekha", "Jaipur"])
fobj.writerow(["e2", "Rohini", "Udaipur"])
f.____________ #Statement-4
_______ open("Employee.csv","r") as f: #Statement-5
readobj=csv._________ #Statement-6
for row in readobj:
print(row)
f.close()
50 Identify the suitable code for blank space in the line marked as Statement-1.
a. csv file
b. CSV
c. csv
d. cvs
51 Identify the missing code for blank space in line marked as Statement-2.
a) "Employee.csv","w"
b) "Employee.csv","wb"
c) "Employee.csv","r"
d) "Employee.cvs","r"
52 Choose the function name (with argument) that should be used in the blank space of line marked
as Statement-3.
a. reader(f)
b. reader(Employee)
c. writer(f)
d. writer(Employee)
53 Identify the suitable code for blank space in line marked as Statement-4.
a. reader()
b. close()
c. load()
d. dump()
54 Identify the suitable code for blank space in the line marked as Statement-5.
a. fopen
b. for
c. with
d. while
55 Choose the function name that should be used in the blank space of line marked as
Statement-6 ?
a. reader(f)
b. read()
c. readrows()
d. readlines(f)

You might also like