1.sel
ectthel
i
stcompr ehensi
oncodeequi
val
entt
othebel
owscr
ipt
.
sum=[]
forxi
nrange(1,
3):
foryi
nr ange(3,6)
:
sum.append(x+y
)
1.
sum=[x+yf orxinrange(1,
3)foryi nrange(
3,6)]
2.
sum=forxinrange(1,
3)foryinr ange(3,
6)printx+y]
3.
sum=[ret
urnx+yf oryinrange(1,3)forxinr
ange( 3,
6)]
4.
sum=[forxinrange(1,
3)foryinr ange(3,
6)returnx+y]
2.whi
chf
unct
ioni
susedt
oreadt
wochar
act
ersf
rom af
il
eobj
ecti
nfi
l
e?
a.i
nfi
le.
readl
ine(2)
b.i
nfi
le.
read(
2)
c.i
nfi
l
e.read(
)
d.i
nfi
le.
readl
ines(2)
3.whi
chf
unct
ioni
susedt
owr
it
ethedat
aint
hebi
nar
yfor
mat
?
a.dump
b.wri
te
c.out
put
d.al
loftheabov
e
4.
whi
chcol
l
ect
ioni
susedt
ost
oreuni
quev
alues?
l
i
st/
dict
/tupl
e/set
5.
ident
if
ytheout
putpr
int
((2,
4)+(
6,8)
)
a.(2,4,6,
8)
b.error
c.{4,6}
d.{(2,4),
(6,
8)}
4.className( obj
ect)
deffi
rst(
):
pri
nt(
"Iam cal
led"
)
defsecond():
pri
nt(
"Igotcal
led"
)
obj=Name()
Name. f
ir
st(obj
)
a.unboundmet hodcal
l
b.boundedmet hodcal
l
c.i
ncorrectobj
ectdecl
arat
ion
d.al
ltheabov e
5.
whi
chi
sappr
opr
iat
etouset
hest
ati
cmet
hodi
nacl
ass?
a.
toaccesstheatt
ri
buteoftheinst
ance
b.t
oinstant
iat
etheclassbasedonthegiv
enpar
amet
er
,c.
toper
formt
heacti
onr
elev
antt
otheclasswit
houti
nst
ant
iat
ingt
hecl
ass
d.t
oaccesst
hest
ati
cmembersoftheclass
6.whi
chf
unct
iondi
spl
aysaf
il
edi
alogf
oropeni
nganexi
sti
ngf
il
e?
a.t
mpf
il
e=askopenfil
ename()
b.t
mpf
il
e=openfi
lename( )
c.t
mpf
il
e=saveasfi
lename()
d.t
mpf
il
e=asksaveasfil
ename(
)
7.defdemo():
t
ry:
pr
int
(1)
fi
nal
l
y:
pr
int
(2)
demo(
)
a.
2
b.
12
c.
1
7.Onwhatcondi
ti
onf
inal
l
ybl
ockget
sexecut
ed?
1.
onspecif
iccondi
ti
on
2.
onexcepti
ons
3.
onerror
s
4.
alway
s
8.sel
ectt
hecor
rectopt
ion
a.noneoftheli
stedopt
ions
b.auserdefi
nedexcept
ioncanbecreat
edbyder
ivi
ngacl
assf
rom err
orcl
ass.
c.cust
om excepti
onsareunav
ail
abl
einpyt
hon
d.auserdefi
nedexcept
ioncanbecreat
edbyder
ivi
ngacl
assf
rom except
ioncl
ass.
9.sel
ectt
hecodesni
ppett
hatdi
vi
debyzer
oer
rorwi
ther
rormessage"numbercannotbedi
vi
dedwi
th
zero"
a.t
ry:1/except:
rai
se
b.t
ry:1/exceptaxe: pr
int(e)
c.t
ry:
1/exceptZer oDivi
sionError
:print
("
numbercannotbediv
idedwi
thzer
o")
d.t
ry:1/exceptValueError
: pr
int(
("numbercannotbediv
idedwit
hzer
o")
10.i
denti
fyt
heoutput
-
forii
n[1,
0]:
pri
nt(
i+1)
a.1
b.21
c.11
, 11.
ident
if
ytheout
put
y=["
test
",'
Done’]
foriiny:
i
.upper
()
pri
nt(y)
a.['
test
',
'
Done']
b.['
TEST',
'DONE']
c.noneoft hel
ist
edopt
ions
d.[None,None]
12.
sel
ectt
hecor
rectmat
ch
1._
_ i
ter__2.next
a.met hodthatiscal
l
edai ni
ti
ali
zat
ionofani
terat
or
b.theiterat
ornextmethodretur
nsthenextv
aluefort
hei
ter
abl
e.
a.1-a2-
b
b.*
**
b.*
***
d.*
**
13.numbers=[
2,4,
6,
8,1]
newnumbers=tuple(
map(
lambdax:
x*x,
number
s))
pri
nt(
newnumbers)
a.(
4,16,
36,64,
1)
b.(
2,4,
6,8,
1)
c.[
2,4,
6,
8,1]
d.[
4,16,
36,64,
1]
14.
whati
stheo/
p
defstri
ng_ reverse(st
r1):
str
2=" "
i
ndex=l en(str1)
whileindex>0:
str2+=st r1[i
ndex-1]
i
ndex=i ndex-1
ret
urnst r2
pri
nt(str
ing_ r
ev er
se('
5678ABCD'
))
a.5678ABCD
b.8765DCBA
c.DCBA8765
d.noneoftheabov
e
14.
whi
choft
hef
oll
owi
ngcodeusesi
nher
it
ance?
a.cl
assHel
l
o:Passcl
asswor
ld(
Hel
l
o):
Pass
b.cl
assHel
lo:
Pass
ectthel
i
stcompr ehensi
oncodeequi
val
entt
othebel
owscr
ipt
.
sum=[]
forxi
nrange(1,
3):
foryi
nr ange(3,6)
:
sum.append(x+y
)
1.
sum=[x+yf orxinrange(1,
3)foryi nrange(
3,6)]
2.
sum=forxinrange(1,
3)foryinr ange(3,
6)printx+y]
3.
sum=[ret
urnx+yf oryinrange(1,3)forxinr
ange( 3,
6)]
4.
sum=[forxinrange(1,
3)foryinr ange(3,
6)returnx+y]
2.whi
chf
unct
ioni
susedt
oreadt
wochar
act
ersf
rom af
il
eobj
ecti
nfi
l
e?
a.i
nfi
le.
readl
ine(2)
b.i
nfi
le.
read(
2)
c.i
nfi
l
e.read(
)
d.i
nfi
le.
readl
ines(2)
3.whi
chf
unct
ioni
susedt
owr
it
ethedat
aint
hebi
nar
yfor
mat
?
a.dump
b.wri
te
c.out
put
d.al
loftheabov
e
4.
whi
chcol
l
ect
ioni
susedt
ost
oreuni
quev
alues?
l
i
st/
dict
/tupl
e/set
5.
ident
if
ytheout
putpr
int
((2,
4)+(
6,8)
)
a.(2,4,6,
8)
b.error
c.{4,6}
d.{(2,4),
(6,
8)}
4.className( obj
ect)
deffi
rst(
):
pri
nt(
"Iam cal
led"
)
defsecond():
pri
nt(
"Igotcal
led"
)
obj=Name()
Name. f
ir
st(obj
)
a.unboundmet hodcal
l
b.boundedmet hodcal
l
c.i
ncorrectobj
ectdecl
arat
ion
d.al
ltheabov e
5.
whi
chi
sappr
opr
iat
etouset
hest
ati
cmet
hodi
nacl
ass?
a.
toaccesstheatt
ri
buteoftheinst
ance
b.t
oinstant
iat
etheclassbasedonthegiv
enpar
amet
er
,c.
toper
formt
heacti
onr
elev
antt
otheclasswit
houti
nst
ant
iat
ingt
hecl
ass
d.t
oaccesst
hest
ati
cmembersoftheclass
6.whi
chf
unct
iondi
spl
aysaf
il
edi
alogf
oropeni
nganexi
sti
ngf
il
e?
a.t
mpf
il
e=askopenfil
ename()
b.t
mpf
il
e=openfi
lename( )
c.t
mpf
il
e=saveasfi
lename()
d.t
mpf
il
e=asksaveasfil
ename(
)
7.defdemo():
t
ry:
pr
int
(1)
fi
nal
l
y:
pr
int
(2)
demo(
)
a.
2
b.
12
c.
1
7.Onwhatcondi
ti
onf
inal
l
ybl
ockget
sexecut
ed?
1.
onspecif
iccondi
ti
on
2.
onexcepti
ons
3.
onerror
s
4.
alway
s
8.sel
ectt
hecor
rectopt
ion
a.noneoftheli
stedopt
ions
b.auserdefi
nedexcept
ioncanbecreat
edbyder
ivi
ngacl
assf
rom err
orcl
ass.
c.cust
om excepti
onsareunav
ail
abl
einpyt
hon
d.auserdefi
nedexcept
ioncanbecreat
edbyder
ivi
ngacl
assf
rom except
ioncl
ass.
9.sel
ectt
hecodesni
ppett
hatdi
vi
debyzer
oer
rorwi
ther
rormessage"numbercannotbedi
vi
dedwi
th
zero"
a.t
ry:1/except:
rai
se
b.t
ry:1/exceptaxe: pr
int(e)
c.t
ry:
1/exceptZer oDivi
sionError
("
numbercannotbediv
idedwi
thzer
o")
d.t
ry:1/exceptValueError
: pr
int(
("numbercannotbediv
idedwit
hzer
o")
10.i
denti
fyt
heoutput
-
forii
n[1,
0]:
pri
nt(
i+1)
a.1
b.21
c.11
, 11.
ident
if
ytheout
put
y=["
test
",'
Done’]
foriiny:
i
.upper
()
pri
nt(y)
a.['
test
',
'
Done']
b.['
TEST',
'DONE']
c.noneoft hel
ist
edopt
ions
d.[None,None]
12.
sel
ectt
hecor
rectmat
ch
1._
_ i
ter__2.next
a.met hodthatiscal
l
edai ni
ti
ali
zat
ionofani
terat
or
b.theiterat
ornextmethodretur
nsthenextv
aluefort
hei
ter
abl
e.
a.1-a2-
b
b.*
**
b.*
***
d.*
**
13.numbers=[
2,4,
6,
8,1]
newnumbers=tuple(
map(
lambdax:
x*x,
number
s))
pri
nt(
newnumbers)
a.(
4,16,
36,64,
1)
b.(
2,4,
6,8,
1)
c.[
2,4,
6,
8,1]
d.[
4,16,
36,64,
1]
14.
whati
stheo/
p
defstri
ng_ reverse(st
r1):
str
2=" "
i
ndex=l en(str1)
whileindex>0:
str2+=st r1[i
ndex-1]
i
ndex=i ndex-1
ret
urnst r2
pri
nt(str
ing_ r
ev er
se('
5678ABCD'
))
a.5678ABCD
b.8765DCBA
c.DCBA8765
d.noneoftheabov
e
14.
whi
choft
hef
oll
owi
ngcodeusesi
nher
it
ance?
a.cl
assHel
l
o:Passcl
asswor
ld(
Hel
l
o):
Pass
b.cl
assHel
lo:
Pass