Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Python_Practice_MCQ with Answers

Rating
-
Sold
-
Pages
17
Grade
A+
Uploaded on
26-12-2023
Written in
2021/2022

This docuement provide a complete set of python mcqs and answer keys

Institution
Course

Content preview

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

Written for

Course

Document information

Uploaded on
December 26, 2023
Number of pages
17
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sohansarkarm13

Get to know the seller

Seller avatar
sohansarkarm13 Academy of Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions