0% found this document useful (0 votes)
8 views

Python 4

Uploaded by

arunachalam .r
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)
8 views

Python 4

Uploaded by

arunachalam .r
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/ 15

\_ & i.

HlrtitHFffltmC'CDGnflftffD

I l ! l ! 11 1 t( ! f ( ti II I I ( JI I I 11I

Deep Dive - Functions, OOPs, Modules, Errors and Exceptions > Python Quiz IV


sys.path is used to find the paths where python search for the modules. Smith, a python developer • 0 Marks
wants to add a path to this list. Which of the following command should he execute?

0 sys. path.extend("path")

0 sys. patl1.aclk:l("pat h") Your Answer

(2) It is not possible to add any pa th

ft sys.path.append("pa th") Coner t Answer

<O> View explanati on

+- Previous

pe here to sear ch lh11ifa:'j ~t ti Ill II Iii ,• ~; Ill


1 I l ! 1 1 ]!JI 1t ! I t ii II 1 l l lj I I I 1j

Deep Dive - Functions, OOPs. Modules, Errors and Exceptions > Python Quiz IV


Predict the output • 2
class Test
def _init_(self):
try:
print("Welcome to init method 11
)

ra ise ZeroDivisionError
fi nally:
pri nt("! wi ll always execute")
def method1 (self):
try:
self. method2()
except:
print("Excepti on handl ed")
ra ise Zero Divisi onError

def met hod2(self,):


print("we lcome to method2")
raise lndexError

+- Previous

P Tvoe here to search


Deep Dive - Functions, OOPs, Modules, Errors and Exceptions > Python Quiz IV

print("welcome to method2")
raise lndexError
try:
TestQ.method1 ()
except:
print("handled outside")
finally:
print("it executes finall!y'')

0 Welcome to init rnethod


I wi ll always execut e

0 Welcome to init method


some exception occured
1 will always execute

welcom e to method2
Exception handled
handled outside
it executes finally

=> Type here to search


Deep Dive - Functions, OOPs, Modules, Errors and Exceptions > Python Quiz IV

0 Welcome to init method


I will always execut e
ZeroDivi sionError Except ion

0 \\'elcome to irnt method


so,ne exception occured
I ,vi 'I always execute
welcome to method2
Exception handled
tiandl ed outside
1t executes finally

• Welcome to 1nit method


I will always execute
handled outside
tt executes fina lly ect r1n

~) V1elcome to in1t method


z1:,ou1v1s1onEr101 Exception
• exec tes finally

+- Previous I
T pe here to si=>ar,h
eep Dive - Functions, OOPs, Modules, Errors and Exceptions > Python Qui.z IV

1'1111111

Alan, a python deME1IOper has executed the below oode. Wtlat is the significance of writing Line • 0
8? .I
import sys
class wron:~,I
pass
I I

try:
if no
rai
111
except
1

print(

0 This st atern

correct Answe
Tnis will print tll.

• Your Answer
>eep Dive - Functions, 00 Ps, Modules, Errors and Exceptions > Python Quiz IV


try:
• OMar
list1 =[1,2,3,4]
print(list1 [4])
except:
a,b,c~__traceback=sys.exc_info()
# Enter the code to print the Line Numbier where the exception has been thrown
I. 1::, II" I

isre01u1r,el 1ne of cod e

•0
Correct Answer

(~) print(a)


Your Answer
Predict the output of the below code: • 2 Marks

var'1 =1 o
var2=0
list1 =[1,2,3]
list1 [3]=var
print(Hst

except:
print('S
except (V
print(' lt

(~) It is a value error

here to search
nsh j= l'1i~.~ 1
list1 [3]=var1 /var2
print(list1 [31)

xcept
print('Some E .i
1

,'

except (ValueEr
• (' . 'I'
pnnt It is a Vi .

0
Correct A•1swer
• Error: except must

<O> Viev,1 explanation


■ Predict the output of the below snippet:
• o Marks

import re
1,

11
Str = Python is d. ,. and Python is awesome 11

fo r i in re.fmditer("Python'\ Str),:
locTuple = .$,p~tl
1i
1

pri nt(locTupll '


I

pri nt (type(locTu ~ I,

0 (0,6)
<class 'tuple'::•

0 (0,6)
-=class ':Jple·>
<37,.13;, Your A 1swer
-=class 'tuple;,

._ Previous

1ere to search
Deep Dive - Functions, OOPs, Modules, Errors and Exceptions > Python Quiz IV
· - - - -r · - · · - r - - - · \I

print(locTuple)
pri nt(type(locTu pie))

8 t0,6)
<class 'tu ple'>

(0,6)
<class 'tu ple'>
<37,43>
<class 'tuple> Your Answer

<0,6)
<c 1as s 'list'>
<37,43>
<c.ass 'I st'>

(37,43)
<cl ass 'tuple>

O V1ev1 explanation

+- Previous
eep Dive - Functions, OOPs, Modules, Errors and Exceptions 1> Python Quiz IV

■ Predict the output of the below snippet:


import re

Str = "sat, hat, mat, pat"

partStr = re.findall("[s=m]at", Str)

for i in someStr:
print(i)

sat
hat
mat

No Outout

l l t: ! \
• Error: Bad character ran~Je

+- Previous
~P Dive - Functions, 00 Ps, Modules, Errors and Exceptions > Python Quiz IV

■ Analyze the snippet and predict the output:


•2M

try:
var1 =1 o
var2=0
result=
prin
print('
finall
pri

0 hi

(~ hello
hi
,~ Ft nc·tmn$. c~0 Ps l\forlult'~. l;m),~ ;lnd rxc<11>tionn \ t1y1lmn r1ul1 IV

, ~rt~, 0
\ J r2 =D
resu t=\ an \ ar2
prnt,result~
pr·nt( hello )
fin ally:
print(hi')

hi

0 hello
ni

0.•_/ ::rror: except is missing

• Error. lrvclid Syntax

<O> view exp anat on

.- Previous
~ -, .. ., .. _~ -~ -~ co classroom/quiz/4/163/17
-~ --
111- 1
l_:o ur :,,;1::,l_:0 11te 11t

ep Dive - Fu nc tio ns ,
00 Ps, Mo du les , Error
s and Exceptions >
Python Quiz IV


Which am on g th e fo
llo wi ng co m m an ds is
used to return a mapp
en vir on m en t? ing object representing
the string • oMar

• print(oSil e1~1i,1)
1
Ill
l'I
1

Your Answer


I I

Correc t Answe1

( ~) print(os .nc1bfo)

<O> View explanati on

+- Previous
I learning-tnsdc,edurek
a.co/classroom/qui2/411

iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
ii-------------------;;;;;;;;;;;;
;;;==~~=====: :: :: -- --
De ep Dive - Functio ~ -- -J
ns. OOPs, Modules,
Err ors and Exception
s > Python Quiz IV

■ Which among the follo


wing commands is us
ed to print the parent pr
ocess id?

• print(os .getppidO)

Correct

0 print(os.get pi dO)
Your

2 print(os. picl())

Z pri nt( os.getprocessid()


)

<O> View explanation

You might also like