0% found this document useful (0 votes)
38 views5 pages

Sample Paper Cs Xii

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)
38 views5 pages

Sample Paper Cs Xii

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/ 5

23 Name the function to read from CSV file.

a) read) b) csv.reader() )esv read() d) read csv)


24Write full form of CSV
a) Comma separated values b)Comma settled values
c) Common separated values d) None of the above
25 An existing CSV file if open in 'w' mode writing data then:
a) new data will be added at the end of file
b)new data will be added at the beginning of file
c)Old data will be lost and new data will be stored.
d) An Error will occur.

Section -B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions from thís section. Choose the
best possible option.
26What will be the output of following Python Code:
if 5>2 or 8<5 and 0 :
print(Hello")
else:
print("Welcome")
a) Error b)Hello c) Welcome d) HelloWelcome
27What will be the output of following Python Code:
X,Y=10,20
Y,Y,Y=Y+2, X+5, Y-2
print(Y)
a) 20 b) 15 c)-18 d) 22
28What willbe the output of following Python Code:
P,S=1,0
for X in range(-5,15,5):
P*=X
S+-X
else:
print(P, " , S)
a) 10#5 b) 10#0 c) 0#10 d) S#10
291 Identify the output of the following Python statements.
LIH6,4,2,9,7]
LI[3:]= 100"
(a) [6,4,2,9,7, 100] (b) [6,4,2,100] (c) [6,4,2,1,0,0] (d) [6,4,2, 1','0', 0']
30 What will be the output of following Python Code:
import random as rd
So,
S ,S2,5)s6
high=4
Guess=rd.randrange(high) +50
for C in range(Guess, 56):
print(C,end="#")
b) 54 # 53 # 54 #55#
a) 50 # 5l# 52 # 53 # 54 # 55#
c) 53 # 54 # 55 # 56 # d) 51 #52 # 53 # 54 #55
31What will be the output of following Python Code:
data=|10,"ram",20,"'sham",30,"'anil"|
data.append("Sunil")
data|2]="Raj"
data.pop)
del data|1]
data<-1|="Magie"
print(data)
a) [10, 'Ram, 'sham, 30,'Sunil)] b-(10,'Raj', 'sham, 30, 'Magic]
[10, 'Magic', 'sham, 30, 'Sunil'] d) [10, 'Ram', 'sham', 30, Magic])
32 What will be the output of following Python Code:
def evenodd(num):
for iin range(len(num):
if num[i|%2--0:
num[il/=2
else:
num[i]*=2
return num
#main-coding
numbers=[10,15,20,25|]
print(evenodd(numbers) #function call
a) [5, 30, 10, 25] b)-{5.0, 30, 10.0, 50]
c) [20.0, 7.5, 40.0, 12.5] d) [20, 15, 40, 12.5]
33 What will be the output of following Python Code:
def convert(name):
N=!
for k in name:
if k.isupper):
N=N+k.lower)
elif k.islower):
N=N+k.upper)
else:
N=N+k
print(N)
#main-coding
convert("Term-1#EXAM")
aytERM-1#exam b) Term-1#EXAM
) exam-1# tERM d) #EXAM Term-1
34 What will be the output of following Python Code:
G=10
def fun10:
global G
G=20
print(G, end="*")
G=G+10
fun1() #call to funl
print(G)
a) 10*20 by20*30 c) 20*20 d) 10*10
Suppose the eontent of Mfle u s
Humpty LDumpty sat on a wall
IHumpty Dumpty had ayeatfoll
Allthe king's horses and all the kingsen
Couldn't put Humpty togethe ogin
What will be the output of he following oode?
myfile open("Myfile.txt")
record myfile.readlínes)
print(len(record)
myfile.close)

a)4 b) 5 c)6

36Suppose the content of "story.txt is -


Always Think Positive,
Never THINK Negative
What willbe the output ofthe following Python code?
filel=open("story.txt","r")
data=filel.read()
word=1
k=data.splito
for iin k:
if i.upper="THINK":
word=word+1
print(word)
filel.close)
a) 0 b)-l )2

371 Suppose the content of "Essay. txt is


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

What willbe the output of the following code?


myfile open("Essay.txt")
line count 0
data = myfile.readlines()
for line in data:
if linel-2|in r'
line count t1
print(line count)
myfile.close)
a) 2 b)3 e)4

38What will be the ouput of followng Python CÛke


A,B=20,10
if A<B:
print("Smaller",end= )
break
print("Number")
else:
print("Greater")
a).Smaller Number b) Smaller c)Greater d) Syntax Error
39 Supposethe content of"Story.txt" is ;
God is one
GOD is everywhere
God bless vou
What will be the content of the file "Kahani.txt" after execution of
Filel =open("Story.txt") following Python Code?
File2 = open(" Kahani.txt",'w')
content = Filel.read()
data=content.split)
for word in data:
if 'o' in word :

File2.write(word+« ")
Filel.close()
File2.close0
a) God One GOD God by God Øne God you
c)God One GOD God you d) God GOD God
40<| Raj has written following program to copy
story.txt file data into fle
complete the program by choosing correct option to fill in blank. kahani.txt. Help Raj to
# Program tocopy Story.txt file into new file
Kahni.txt
filel=open("story.txt","r")
file2=open(" kahani.txt","w")
data=filel.read)
# towrite data in kahani.txt
filel.close)
file2.close)
print("File copied")
a) filel.writedata() b) file2.writedata( ) c) filel.write(data) d) file2.write (data)
417 Syntax of seek function in Python is
myfile.seek(offset,
object. What is the default value of reference point? reference point) where myfile is the file
b)1 c) 2 d) 3
42 The content of text file
INSTITUTE.TXT is :
KVS is a great organization
What will be the content of
INSTITUTE.TXT after execution of following Python code:
filel=open("INSTITUTE.
file.write("of India") TXT","w'")
filel.close(0
a) KVS is a great organization of India
c) KVS is a great organization b)KVS is a great organization of World
d)of India
Raj is trying to write an object objl =(1,2,3,4,5) on a
binary file "test.dat". Consider the following
Page 6 of 2
code written by him.
import piekle
objl = (1,2,3,4,5)
myfile open("test.dat",'wb')
pickle. NStatement 1
myfile.clese( )
Identify the missing code in Statement 1.
a) dump(myfile,objl) bydump(obj l, myfile)
c) write(objl,myfile) d) load(myfile,objl)
44 The content of binary file STUDENT. DATis :
{'rno': 1, 'name':'raja', 'marks' 95.5)
'marks': 78.0)
{'rno : 2, 'name': ram singh', 'marks ': 68.0)
('rno': 3, 'name:'sonia',
'marks' : 85.5)
{'rno' : 4, 'name':'rajesh',
'marks' : 48.0)
{'rno' : 5, 'name':'raj singh',

What will be the output of following Python Code:


import pickle as pk
counter=0
filel=open("student.dat","rb'")
try:
while True:
ree=pk.load(file1)
if ree['marks'}<80:
counter+=1
except EOFError:
print(counter)
filel.close)
b) 3 c)2 d) 6
a) 4
binary file games.dat to athelete.dat. Complete the
45|The following program copies all record from
missing statement
import pickle as pk
filel=open('"games.dat", "rb")
file2=open("athelete.dat", "'wb")
try:
while True:
# statement-1 :to read record
# statement-2 : to write record
except EOFError:
print("file copied ")
filel.close
file2.close)

a) statement-1: rec-pk.load(file2), statement-2: pk.dump(rec,file 1)


b- statement-1: rec-pk. load(file l), statement-2: pk.dump(rec, file2)
c) statement-2: rec=pk.load(file l), statement-1: pk.dump(rec, file2)
d) statement-2: rec-pk.load(file2), statement-1: pk.dump(rec,file1)
46 Suppose the content of "story.txt" is :

You might also like