0% found this document useful (0 votes)
51 views8 pages

12 CS PT 0402 Ans

The document provides instructions for a periodic test for grade 12 computer science students. It contains 4 sections - general instructions, section A with 20 multiple choice questions, section B with 20 short answer questions, and section C with 5 case study questions.
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)
51 views8 pages

12 CS PT 0402 Ans

The document provides instructions for a periodic test for grade 12 computer science students. It contains 4 sections - general instructions, section A with 20 multiple choice questions, section B with 20 short answer questions, and section C with 5 case study questions.
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/ 8

VEDIC VIDYASHRAM SENIOR SECONDARY SCHOOL

TIRUNELVELI-627 358
(Academic Year : 21-22)
Grade : XII COMPUTER SCIENCE (083) CODE : PT-0402
Time : 1.30 hrs Max : 35

General Instructions:
1. The question paper is divided into 3 Sections - A, B and C.
2. Section A, consist of 20 Questions. Attempt all questions.
3. Section B, consist of 20 Questions. Attempt all questions.
4. Section C, consist of 5 case study based Questions. Attempt all questions.

PERIODIC TEST-4
SECTION-A
Each carry 0.5 Marks ( 20 * 0.5 = 10)
To open a file c:\scores.txt for reading, we use
a) infile = open(“c:\scores.txt”, “r”)
01 b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)
To open a file c:\scores.txt for appending data, we use
a) outfile = open(“c:\\scores.txt”, “a”)
02 b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
To read two characters from a file object infile, we use
03 a) infile.read(2) b) infile.read()
c) infile.readline() d) infile.readlines()
To read the next line of the file from a file object infile, we use
04 a) infile.read(2) b) infile.read()
c) infile.readline() d) infile.readlines()
The readlines() method returns
05 a) str b) a list of lines
c) a list of single characters d) a list of integers
What is the use of “w” in file handling?
06
a) Read b) Write c) Append d) None of the mentioned
Which function is used to write a list of string in a file
07 a) writeline() b) writelines()
c) writestatement() d) writefullline()
Which function is used to read all the characters?
08 a) Read() b) Readcharacters()
c) Readall() d) Readchar()
Is it possible to create a text file in python?
09 a) Yes b) No
c) Machine dependent d) All of the mentioned
10 Which of the following is modes of both writing and reading in binary format in file.?
1
a) wb+ b) w
c) wb d) w+
Which of the following is not a valid mode to open a file?
11
a) ab b) rw c) r+ d) w+
How do you delete a file?
12 a) del(fp) b) fp.delete()
c) os.remove(‘file’) d) os.delete(‘file’)
How do you get the name of a file from a file object (fp)?
13 a) fp.name b) fp.file(name)
c) self.__name__(fp) d) fp.__name__()
What happens if no arguments are passed to the seek function?
a) file position is set to the start of file
14 b) file position is set to the end of file
c) file position remains unchanged
d) error
How do you close a file object (fp)?
15 a) close(fp) b) fclose(fp)
c) fp.close() d) fp.__close__()
How do you rename a file?
a) fp.name = ‘new_name.txt’
16 b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name)
Which function is used to read single line from file?
17 a) Readline() b) Readlines()
c) Readstatement() d) Readfullline()
What is the correct syntax of open() function?
a) file = open(file_name [, access_mode][, buffering])
18 b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) none of the mentioned
What is unpickling?
a) It is used for object serialization
19 b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned
What is the use of seek() method in files?
a) sets the file’s current position at the offset
20 b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned
SECTION-B ( 20 * 1 = 20)
What is the output of this program?
str = input("Enter your input: ");
21 print "Received input is : ", str
a) Enter your input: [x*5 for x in range(2,10,2)].
Received input is : [x*5 for x in range(2,10,2)].
2
b) Enter your input: [x*5 for x in range(2,10,2)].
Received input is : [10, 30, 20, 40].
c) Enter your input: [x*5 for x in range(2,10,2)].
Received input is : [10, 10, 30, 40].
d) None of the mentioned
What is the output of this program?
str = raw_input("Enter your input: ");
print("Received input is : ", str)
a) Enter your input: Hello Python
Received input is : Hello Python
22
b) Enter your input: Hello Python
Received input is : Hello
c) Enter your input: Hello Python
Received input is : Python
d) None of the mentioned
What is the output of this program?
import sys
sys.stdout.write(' Hello\n')
sys.stdout.write('Python\n')
23
a) Compilation Error b) Runtime Error
c) Hello Python
d) Hello
Python
What is the difference between r+ and w+ modes?
a) no difference
b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for
24 w+
c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for
r+
d) depends on the operating system
What is the use of truncate() method in file?
a) truncates the file size
25 b) deletes the content of the file
c) deletes the file size
d) none of the mentioned
What is the output?
f = None
for i in range (5):
with open("data.txt", "w") as f:
26
if i > 2:
break
print(f.closed)
a) True b) False c) None d) Error
To read the next line of the file from a file object infi, we use
27 (a) infi.read(all)
(b) infi.read()

3
(c) infi.readline()
(d) infi.readlines()
A local variable having the same name as that of a global variable, hides the global variable in its
function.
a) True
28
b) False
c) Error
d) Not defined
_____ arguments are the named arguments with assigned values being passed in the function
29 call statement.
a) Keyword b) positional c) default d) None
The values received in the function definition/header are called _____.
a) parameter

30 b) values
c) identifier
d) None of the above
_____ act as a means of communication between the called and calling function.
31
a) Values b) Argument c) module d) variable
What is the order of resolving scope of a name in a Python program?
(L: Local namespace, E : Enclosing namespace, B: Built-In Namespace, G: Global namespace)
(a) BGEL
32
(b) LEGB
(c) GEBL
(d) LBEG
Which of the following statements is not true for parameter passing to functions?
(a) You can pass positional arguments in any order.

33 (b) You can pass keyword arguments in any order.


(c) You can call a function with positional and keyword arguments.
(d) Positional arguments must be before keyword arguments in a function call.
Pick one the following statements to correctly complete the function body in the given code
snippet.
def f(number):
34
# Missing function body
print(f(5))

4
(a) return "number"
(b) print(number)
(c) print("number")
(d) return number
What happens if the base condition isn't defined in recursive programs?
(a) Program gets into an infinite loop

35 (b) Program runs once


(c) Program runs n number of times, where n is the argument given to the function
(d) An exception is thrown
What is the output?
f = None
for i in range (7):
with open("data.txt", "a") as f:
36
if i > 2:
break
print(f.closed)
a) True b) False c) None d) Error
def increment(n):
n. append(40)
return n[0], n[1], n[2], n[3]
L = (10,20,30)
mi, m2, m3, m4 = increment (L)
print(L)
print(mi, m2, m3, m4)
print(L[3] < m4)
a) [10, 20, 30, 40]
37
10 20 30 40
False
b) [10, 20, 40,30]
10 20 30 40
True
c) [10, 20, 30, 40]
10 20 30 40
None
d) None of the above
What is the output of following code fragments?
def increment(n):
n. append([4])
38
return n
L = [1, 2, 3]
M = increment(L)

5
print(L, M)
a) [1, 2, 3, [4]] [1, 2, 3, [4]]
b) (1, 2, 3, [4]] [1, 2, 3, [4])
c) {1, 2, 3, [4]] [1, 2, 3, [4]}
d) [1, 2, 3, (4)] [1, 2, 3, [4]]
What will the following function return?
def add(x, y, z):
39 print (x + y + z)
add(10,20,30)
a) 60 b) 70 c) 50 d) None
In the following code, which variables are in the same scope?
def func1():
a=1
b=2
print(a,b)
func2()
def func2():
c=3
d=4
print(c,d,e)
e=5
func1()
40 print(e+10)
a) 1 2
345
15
b) 1 1
345
15
c) 1 1
346
15
d) 1 1
345
17
SECTION-C
What is the output of this program?
fo = open("foo.txt", "rw+")
print ("Name of the file: ", fo.name)
# Assuming file has following 5 lines
# This is 1st line
41 # This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line
for index in range(5):
line = fo.next()
6
print "Line No %d - %s" % (index, line)
fo.close()
a) Compilation Error b) Syntax Error
c) Displays Output d) None of the mentioned (Ans : Value Error)
Trace the following code and predict the output produced by it
def power (b, p):
y = b ** p
return y
def calcsquare (x) :
42 a = power(x,2)
return a
n=5
result = calcsquare(n) + power (3,3)
print(result)
a) 42 b) 42.5 c) 52 d) None
What happens if the file is not found in the code shown below?
a=False
while not a:
try:
f_n = input("Enter file name")
43
i_f = open(f_n, 'r')
except:
print("Input file not found")
a) No error b) Assertion error
c) Input output error d) Name error
def increment(n):
n. append((44))
return n
L = [11, 22, 33]
M = increment(L)
44
print(L, M)
a) [11, 22, 33, 44] [11, 22, 33, 44]
b) (11, 22, 33, 44] [11, 22, 33, 44)
c) [11, 22, 33, [44]] [11, 22, 33, 44]
d) [11, 22, 33, (44)] [11, 22, 33, 44]
def increment(n):
n. append([49])
return n[0], n[1], n[2], n[3]
L = [23, 35, 47]
mi, m2, m3, m4 = increment (L)
print(L)
45
print(mi, m2, m3, m4)
print(L[3] == m4)
a) [23, 35, 47, [49]]
23 35 47 [49]
True
b) [33, 45, 47, [49]]
7
23 35 57 [49]
True
c) [23, 35, 49, [49]]
23 54 47 [49]
True
d) [23, 75, 47, [49]]
23 35 47 [49]
True
*********

You might also like