You are on page 1of 13

HALFYEARLYEXAMI NATI ON( 2021-

2022)
Subj
ect
:Comput erScience
Grade:XII
Ti
meAl lowed:90mi nutes Max.Mark:35
Date:22.09.2021 Day:Wednesday
__
__________
_ _
_____
______
___
_______
_____
____
_______
__ __
____
____
____
_____
___
____
____
___
_
__
__________
_ _
__
GeneralInst
ructi
ons:
1. Pleasereadtheinstr
uct
ionscaref
ull
y
2. Thi
sQuest
ionPaperi
sdi
vi
dedi
nto03sect
ions,
viz.
,Sect
ionA,
Sect
ionBandSect
ion
C.
3. Sect
ionA,
consi
stof25quest
ions(
1-25)
.At
temptany20.
4. Sect
ionB,
consi
stof24quest
ions(
26-
49)
.At
temptany20.
5. Sect
ion C,consi
stof6 compet
ency
-based quest
ions (
50-
55)
.At
temptany 5
quest
ions.
6. Ov
eral
lat
tempt45quest
ionsoutof55quest
ions.
7. Mar
kswi
l
lber
educedt
o35.
8. Al
lquest
ionscar
ryequal
mar
ks.

SECTI
ONA

Answerany20quest
ionsoutofthegi
ven25quest
ionsonRev
isi
onofPy
thont
opi
cs
cover
edinCl
assXIandFuncti
ons. (
1x20=20
marks)

1.Whi chofthefoll
owi
ngt
ermi
simmut
abl
e?
a)Tupl es
b)Strings
c)List
d)Tupl esandSt
ring
Ans.TuplesandStri
ng

2.Wr i
tetheout
putoft
hef
oll
owi
ng
>>>7==3.5**2
a)True
b)False
c)7
d)Notequival
ent
Ans.Fal
se

3.Howmanyspacesar
ether
einonei
ndent
ati
onl
evel
?
a)2
b)3
c)4
d)7
Ans.4

4.Whi choft hefol


lowi
ngcannotbeav ar
iabl
e?
a)upon
b)in
c)i
t
d)on
Ans.in
5.Smal lestunit
/el
ementofpythonprogr
am iscal
l
ed_
___
___
___
___
_.
Token
Str
ing
Vari
able
Keyword
Ans.token
6.Wr it
et heoutputoft
hefol
lowing:
a,b=2, 6
a,b,b=a+b, 2,3
pri
nt(a,
b)

a)2,
6
b)6,
2
c)8,
3
d)8,
6
Ans.
8,3

7.Wr
it
ethel
engt
hoff
oll
owi
ngt
upl
e:

T1=(
1,(
2,3)
,(
((34,
56)
,45,
67)
,39)
)

a) 1
b) 3
c) 5
d) 7
Ans.3

8.Wr
it
etheout
putoft
hef
oll
owi
ng:

T1=( 1,(2,'
a'
),(
3,'
b'
,'
c'
),
(7,
'd'
,'
e'
,'
f'
))
print(
len(T1))
print(
T1[1][
0])
print(
7i nT1[3]
)
a)1;
2; 7
b)4;
2; True
c)1;
2; True
d)4;
2; False
Ans.4;
2;t
rue

9.Wr
it
etheout
putoft
hef
oll
owi
ng:

T1=('a'
)*3
pr
int
(T1)
pr
int
(type(
T1)
)

a)aaa;
<cl ass'st
r'
>
b)333;<class'st
r'
>
c)aaa;
<' str'
>
d)aaa;
<cl ass'i
nt'
>

Ans.aaa;
<cl
ass'
str
'>

10.
Wri
tet
heout
putoft
hef
oll
owi
ng:

T1=(1,2,3,
4,5,
6,7,
8)
pr
int
(T1[:
])

a)(1,
2,3,
4,5,
6,7,
8)
b)()
c)(2,
3,4,
5,6,
7,8)
d)(1,
2,3,
4,5,
6,7)

Ans.
(1,
2,3,
4,5,
6,7,
8)

11.
Wri
tet
heout
putoft
hef
oll
owi
ng:

T1=('Hockey
','
Cri
cket
',
'Foot
bal
l
')
pr
int
(max(T1))

a)Hockey
b)Cri
cket
c)Footbal
l
d)8

Ans.Hockey

12.
Writetheout
putoft
hef
oll
owi
ng:
 
  
 
   
a=“ Myageis”
 
   b=16
 
   pri
nt(
a+b)

a)Myagei
s16
b)Myagei
s
c)16
d)ERROR

Ans.ERROR

13.Trav
ersi
ngalistcanbedonewi
tht
hehel
pof
 __
___
___
_
a)loop
b)if
c)if–el
if
d)Noneoft heabove

Ans.
 loop

14.
Wri
tet
heout
putoft
hef
oll
owi
ng:

l
ist
1=[3,
2,
5,
7,3,
6]
l
ist
1.r
emove(3)
pri
nt(
sum(l
ist
1))
a)23
b)20
c)19
d)Noneoftheabove

Ans.
 23

15.
Whi
choft
hef
oll
owi
ngi
snotal
i
stoper
ati
on?

a)I
ndexing
b)Sl
ici
ng
c)Di
v i
ding
d)Concatenat
ion

Ans.
 Di
vi
ding

16.
Namet
heoper
atorwhi
chi
susedi
nthef
oll
owi
ngpr
intst
atement
.

pr
int
(L1*2)

a)Concatenati
on
b)Repeti
ti
on
c)Member shi
p
d)Noneoft heabov
e

Ans.Repet
it
ion

17.Theforl
oopinPyt
honi
san_
___
___
___
___
a)EntryContr
oll
edLoop✓
b)ExitContr
oll
edLoop
c)Bot
hoftheabove
d)Noneoftheabov
e

18.Al oopbl
ocki
npy
thonst
art
swi
tha–
a);(
semicolon)
b),(
comma)
c):(
colon) 

d)#(hash)

19.Whichoft
hefol
lowi
ngi sTr
uer egardingloopsinPython?
a)Loopsshouldbeendedwithkeyword“ end”.
b)Nol oopcanbeusedtoi
teratet
hrought heelement sofstr
ings.
c)continuei
susedtocont
inuewit
ht heremai ni
ngst at
ementsi nsi
det
hel
oop.
d)breakcanbeusedtobri
ngcontroloutoft hecurrentl
oop.✓

20.Whichter
m descr
ibesal
oopt
hatcont
inuesr
epeat
ingwi
thoutat
ermi
nat
ing(
endi
ng)
condi
ti
on?
a)I
nfinit
eLoop✓
b)Conditi
onalLoop
c)Unli
mi t
edLoop
d)SequenceLoop

21.Todi splaythest
art
ingi
ndexf
ort
hesubst
ri
ng‘
vo’
a)str
.disp(
‘vo’)
b)str.
start
ind( ‘
vo’
)
c)str
.fi
nd(‘
v o’)✓
d)Noneoft heabov e

22.Whatwi l
l betheout
putoft
hef
oll
owi
ngpr
ogr
ammi
ngcode?
x=”AmaZi ng”
pri
nt(x[
3:]
,”and”
,x[:
2])
a)Amazi ngandZI
b)aZingandZi n
c)ZingandAm ✓
d)Azingandzi n

23.
The_ _
_ _
___
___f
unct
ionr
etur
nst
heexactcopyoft
hest
ri
ngwi
tht
hef
ir
stl
ett
eri
n
uppercase.
a)fi
nd()
b)copy(
)
c)upper(
)
d)capi
tal
ize()✓

24.Whatistheoutputoft
hef
oll
owi
ngcode:
example=“hel
le”
example.
fi
nd(“
e”)
a)Error
b)-1
c)1✓
d)bot
hbandc
Ans:bot
hbandc

25.Whatistheoutputofthefol
l
owi
ng?
pr
int(
‘Ab!
2’.
swapcase())
a)AB!@
b)ab12
c)aB!2✓
d)aB1@
SECTI
ONB
Thissect
ionconsist
sof24Questi
ons(26t
o49)
.At
temptany20quest
ions.

26.
Eval
uat
ethef
oll
owi
ngexpr
essi
ons

12%4+6+4/
/3
a)4
b)6
c)7
d)10

Ans7
27.
Wr i
tetheoutputofthef
oll
owi
ngPy
thoncode:
foriinrange(
2,7,
2):
pri
nt(i*‘$’
)
a)2$
4$
6$
b)$$✓
$$$$
$$$$$$
c)2$4$6$
d)Noneoft heabove

28.
Findandwr i
tetheoutputoft
hef
oll
owi
ngpy
thoncode:
x=“ abcdef”
i=“ a”
whi l
ei i
nx:
print(
i,end=”“ )
a)a
b)aaaaaa
c)aaaaaa…i nf
ini
teti
mes✓
d)Codewi ll
generateerror

29.
Findtheout
putoft
hef
oll
owi
ngpr
ogr
am segment
s:
i=0
sum =0
whilei<9:
ifi%4==0:
sum =sum +i
i=i+2
pri
nt(
sum)

a)Inf
ini
teLoop
b)12✓
c)14
d)10

30.Whichofthef
oll
owi
ngcal
ltor
ange(
)inPy
thonwi
l
lnoty
iel
dany
thi
ng?
a)r
ange(-5,-
1)
b)range(
-1,-
5,-1)
c)r
ange(-5)✓
d)Alloft
heabov e

31.Whatwill
bethef
inal
val
ueofIaf
terexecut
ionoft
hel
oop:
forIi
nr ange(
10):
pri
nt(I
)
a)0to10
b)0to9✓
c)None
d)Error

32.Answerthef ol
lowing:
A)Assertion:b=“ Hell
o,Wor l
d!”pri
nt(b[
:5])wi
llgi
veoutput“
Hell
o”
(R)Reason: Thiswill
givegetthechar actersf
rom st
artposi
ti
on(
5not
 i
ncl
uded)
(a)AistruebutRi sfalse
(b)AistrueandRi scor r
ectexplanati
onofA  ✓
(c)AandBbot harefalse
(d)AistruebutRi snotcor r
ectexplanati
onofA

33.Answert hef ol
lowing:
(A)Asser ti
onst r1=”Hello”andst r
1=”Worl
d”t
henpr i
nt(st
r1*3)wil
lgi
ve 
err
or
(R)Reason: *replicatesthest ri
nghencecor
rectoutputwillbe
HelloHelloHell
o
(a)Aist ruebutRi sfalse
(b)Aist ruebutRi snotcor rectexpl
anat
ionofA
(c)AandBbot har efalse
(d)Aisf alseandRi scor rect 
Ans: c
34.Whi chstat ementwi l
ldispl
aythel
astfourcharact
ers?
(a)str[
-4:]

(b)str[
:-
4:]
(c)str
[:
:]
(d)str[
::
-4]

35.
Ms.Sumani sworkingonabi naryfil
eandwantstowr i
tedat
afrom al
istt
oabinar
y
fi
le.Considerli
stobjectasl1,
binaryfil
esuman_li
st.
dat,
andfi
leobj
ectasf.Whi
ch
ofthef ol
l
owi ngcanbet hecorrectstat
ementforher?
a)f=open(‘sum_li
st’,

wb’)
;pickle.
dump( l
1,f
)
b)f=open(‘
sum_l
ist
’,

rb’
);l1=pickle.dump(f)
c)f=open(‘
sum_l
ist
’,

wb’);pickle.l
oad(l1,
f)
d)f=open(‘
sum_l
ist
’,

rb’
);l1=pickle.l
oad(f)
Ans:a
Whichopti
onwil
lbecorrectforr eadingfil
eforsumanf
rom abov
equest
ion?
Ans.f=open(‘
sum_li
st’
,
’rb’)
;l1=pickle.
load(f
)

36.I
nwhi choft hef i
l
emodeexi st
ingdatawillbeintactinbi naryfi
le?
a)ab
b)a
c)w
d)wb
Ans:a
37.Whi choneoft hefol l
owi ngi scor r
ectstat
ement ?
a)i
mpor t–pi ckle
b)pickl
ei mpor t
c)i
mpor tpi ckle
d)Alloftheabov e
Ans:c
38.Findt hecor r
ector derf orst epsfoll
owt oprintdataf rom csvf i
leinl
istobject.
i
. Opent hecsvf i
leinr eadi ngmode–f=open( “demo. csv ”
,”
r”)
ii
. I mpor tcsvmodul e–i mpor tcsv
i
ii
. cl oset hecsvf il
e–f .
close( )
i
v. Usel istobjecttost oret hedat areadf r
om csvusi ngr eader–dat a=csv .reader(
f)
a)i ,i
i
,iii
,iv
b)i v,
ii
i,i,ii
c)i i
,i
v, i
,iii
d)i v,
i,ii
,iii
Ans:d
39.Wr i
tet hemi ssingpy thoncodet ocreateaheaderr owf orCSVf il
e“students.csv
”.
Thecol umnnamesar e: Adm. No,StudentName, Ci t
y, Remar ks
fr
om csvi mportwr iter
………………………………………………………
dt=wr it
er(f
)
dt.writer
ow( [
'
Admno' ,'
St udentName' ,
'
Cit
y',
'Remar ks']
)
f.
close( )

a) f=open(
"st
udents.
csv",
"w",
newline=’’
)
b) fi
l
e=open("
student
s.csv",
"w",
newline=’’
)
c) f=open(
"st
udents.
csv",
"r
",
newline=’’
)
d) fi
l
e=open("
student
s.csv",
"r
b",
newl i
ne=’’
)

Ans.a,
f=open(
"st
udent
s.csv
","
w",
newl
i
ne=’

)

40.
Findandwr it
etheoutputoft
hef
oll
owi
ngpy
thoncode:
deffun(s)
:
k=len(s)
m=""
foriinrange(
0,k)
:
i
f(s[i
].
isupper ()
):
m=m+s[ i
].
lower()
eli
fs[i
].isalpha()
:
m=m+s[ i
].
upper()
else:
m=m+' bb'
print
(m)
fun('
school 2@Com' )

a) school
2@Com
b) SCHOOLbbbbcOM
c) SCHOOL2@Com
d) school
bbbCom

Ans.SCHOOLbbbbcOM

41.Considerthefoll
owingcodeandanswert hequestionsthatfol
low:
Book={1:
'Thri
ll
er'
, 2: '
My ster
y', 3:'
Cri
me', 4: '
Chil
drenStori
es'}
Li
brary={'
5':
'MadrasDiaries',
'6'
:
'MalgudiDays'}
Rameshneedst ochanget het i
tlei
nt hedi
ctionar
ybookf rom ‘
Crime’to‘
Cri
me
Thri
ll
er’
.Hehaswr i
tt
ent hef oll
owingcommand:
Book[‘
Cri
me’ ]
=’Cri
meThr ill
er’
Butheisnotget t
ingtheanswer .Helphim choosethecorrectcommand:
a) Book[2]=’
CrimeThr i
l
ler ’
b) Book[3]=’
CrimeThr i
l
ler ’
c) Book[2]=(’
Cri
meThr ill
er ’
)
d) Book[3]=(‘
CrimeThr il
ler’
)

Cor
rectAnswer
:b

42.Yourt eacherhasgi veny ouamet hod/funct


ionFil
ter
Wor ds()inpyt
honwhi chr ead
l
inesf rom atextfil
eNewsLet t
er.TXT, anddispl
aythosewor ds,whicharelesser
than4char acters.Yourt eachersintenti
onall
ykeptfewbl anksinbetweent hecode
andaskedy outof i
lltheblankssot hatthecodewillr
unt ofinddesir
edresult.Do
theneedf ulwit
ht hef ol
lowingpy t
honcode.
defFilter
Wor ds()
:
c=0
fi
le=open('NewsLett er
.TXT',' ') #Statement -
1
li
ne=f i
l
e. #Statement -
2
wor d= #Statement -
3
forci nword:
i
f : #Statement-4
print
(c)
#Statement -
5

Fi
lt
erWords(
)
Fi
lli
ntheblanki
nst
atement
-2t
oreadt
hedat
afr
om t
hef
il
e.
a) Fi
le.
Read(
)
b) fi
l
e.r
ead()
c) r
ead.
li
nes()
d) r
eadl
i
nes()

Cor
rectAnswer
:b.f
il
e.r
ead(
)

43.Fil
li
nt heblanki nstat
ement-4,
whi
chdi
spl
ayt
hewor
dhav
ingl
essert
han4
character
s.(readQ. No.43)
a)l en(
c)==4
b)l en(
c)<4
c)l en()==3
d)l en()==3
Cor
rectAnswer : l en(c)
<4

44.
Writetheout putofthefol
l
owi
ngcode:
>>>L=[1,2,
3,4,
5,[
6,7,
8]]
>>>print
(L[5])
a) [ 6,7,8]
b) 6, 7, 8
c) Er ror
d) 6

Ans.a.[
6,7,
8]

45.
Wr itetheoutputofthef
oll
owi
ngcode:
L=[0.5*xf orxinrange(
4)]
pr i
nt(L)
a) [0.0, 0.
5,1.
0, 1.
5]
b) ( 0,
.5,1,1.
5)
c) [0.0, 0.
5,1.
0, 1.
5,2.
0]
d)  Error

Ans.a.[
0.0,
0.5,
1.0,
1.5]

46.Wr i
tetheoutputoft
hefoll
owing:
L=[ [
5,7,9,1],[
12,23,
4,9]]
forrinL:
  r.
rever
se()
  foreinr :
    pri
nt(e,end=”“)
a) 1975942312
b) 1975
942312 
c) Er
ror
d)Noneoft heabov e

Ans.B.
 1975
942312

47.
Wri
teast
atementt
opr
int30f
rom t
hegi
vent
upl
e.
a=( “
Sev ent
y”,
[1,
2,3]
,(20,
30,
40)
,“Ei
ght
y”)
a)pri
nt(
a[3][1]
)
b)pri
nt(
a[1][2]
)
c)pri
nt(
a[0][1]
)
d)pri
nt(
a[2][1]
)
Ans.pr
int
(a[
2][1])

48.Fi
lli
nt heblanksi nthef oll
owingcode:
i
mpor t_ _
_________
t=(20, 30,40,50, 60, 70)
A=r andom. randint(1, 3)
B=r andom. randint(
2, 4)
fori_ _______
_r ange( A, B):
pr i
nt(t[
i]
,end=" @" )
a)random; i
n
B)csv;in
C)txt;i
n
D)random; out
Ans.random; in

SECTI
ONC
CaseStudybasedQuest
ions
.
Answerany5quest
ionsoutofthegi
ven6questi
ons.(
1x5=5mar
ks)

SamitaPateli
sapr ogrammer
,whohasrecent
lybeengi
venataskt
owrit
eapy t
honcode
toperfor
mt hefoll
owingCSVfi
leoper
ati
onswit
hthehel
poftwouserdef
ined
funct
ions/modules:

a. CSVOpen( ):t
ocr
eateaCSVfi
lecal
l
edBOOKS.
CSVi
nappendmodecont
aini
ng
i
nfor
mat
ionofbooks–Tit
le,
Aut
horandPri
ce.

b. CSVRead( ):t
odispl
ayt
her
ecor
dsf
rom t
heCSVf
il
ecal
l
edBOOKS.
CSVwher
ethe
fi
eldt
it
lest
art
swit
h'R'
.

Shehassucceededi
nwri
ti
ngpar
ti
alcodeandhasmi
ssedoutcer
tai
nst
atement
s,soshe
hasl
eftcer
tai
nqueri
esi
ncommentli
nes.

i
mport____
____
defCSVOpen(
):
wit
hopen('
books.
csv'
,
' '
,newli
ne='
')ascsvf
:#St
atement
-1
cw= #Statement-
2#Statement
-3
cw.wr
it
erow([
'
Rapunzel'
,
'Jack'
,300]
)
cw.wr
it
erow([
'
Barbi
e'
,'
Doll'
,
900])
cw.wr
it
erow([
'
Johnny'
,'
Jane',
280])

defCSVRead(
):
t
ry:
wit
hopen('books.
csv
',
'r
')ascsv
f:cr= #St
atement
-4
f
orrincr:
i
f : #Stat
ement
-5pr
int(
r)
except
:
pri
nt(
'Fi
leNotFound'
)

CSVOpen(
)CSVRead(
)

YouasanexpertofPy
thonhavetoprov
idethemi
ssi
ngst
atement
sandot
herr
elat
ed
quer
iesbasedonthef
oll
owingcodeofRadha.

49.Choosetheappr
opr
iat
emodei
nwhi
cht
hef
il
eist
obeopenedi
nappendmode
(St
atement1)
a) w+
b) ab
c) r +
d) a
CorrectAnswer:d.a

50.Whichstatementwil
lbeusedtocr
eat
eacsvwr
it
erobj
ecti
nSt
atement2.
a) csv .
wri
ter(csvf
)
b) csv .
wri
ter(csvf
)
c) csv f
.wri
ter()
d) cs.writ
er(csvf)
CorrectAnswer:b.csv .
wri
ter
(csv
f)

51.Choosethecorrectoptionf orSt atement3towrit


ethenamesoft
hecol
umn
headi
ngsintheCSVf il
e,BOOKS. CSV.
a) cw. wri
ter
ow('
Titl
e',
'Author',
'
Pr i
ce')
b) cw. wri
ter
ow(['
Tit
le'
,'
Author '
,
'Price']
)
c) cw. wri
ter
ows('
Titl
e','
Author',
'Pri
ce')
d) cw. wri
ter
ows(['
Titl
e',
'
Aut hor'
,'
Pr i
ce'])
CorrectAnswer:b.cw. writ
erow( [
'Tit
le','
Author
',
'
Pri
ce'
]
)

52.Whichst atementwillbeusedtor
eadacsvf
il
einSt
atement4.
a) cs.read(csv f
)
b) csv .
reader(csvf
)
c) csv f
.read()
d) csv f
.reader(cs)
CorrectAnswer :b.csv .
reader(
csvf
)

53.
Filli
nt heappr
opri
atest
atementtocheckt
hef
iel
dTi
tl
est
art
ingwi
th‘
R’f
or
St at
ement5i ntheabov
eprogram.
a) r[0][
0]=='
R'
b) r[
1] [
0]=='
R'
c) r[0][
1]=='
R'
d) d)r [
1][1]
=='
R'
Cor
rectAnswer
:a.r
[0]
[0]
=='
R'

54.Identi
fyt
hesui t
abl
emodul
efort
hegi
vencode:
a)csvf il
e
b)CSV
c)csv
d)Csv
CorrectAnswer: c)csv

You might also like