Professional Documents
Culture Documents
Python 4
Python 4
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")
+- Previous
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
+- Previous
print("welcome to method2")
raise lndexError
try:
TestQ.method1 ()
except:
print("handled outside")
finally:
print("it executes finall!y'')
welcom e to method2
Exception handled
handled outside
it executes 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
•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
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
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 (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
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
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
.- 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)
+- 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
• print(os .getppidO)
Correct
0 print(os.get pi dO)
Your
2 print(os. picl())