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

Exception Handling, Python Data Structures

handwritten notes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Exception Handling, Python Data Structures

handwritten notes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ExcepBfon

on thadicosuy (0r)unerneebed
Stkaafon Or lunpcked ehor
dustng
knoun as cicepkton.
Boaedly classct ed tuto hoo ypes
Run tne onor.

Thise aL ti eOSS eswing


Out ko VolaHng
VolaHng 4 pn041am nôn
Janquíness gmamiman sules
Eg stng kyntaacally
TnLoprret statrnent.
Pxiyt C'a' +a)

hat OcUss duning


Sihuaion.
BushO9s ae handLd
thuough aptors handleng
S0uttns 4Python.
nalls
ELcepttonal handtng ae Loau

Advastages4 etupttoral handirrgz


superats enon
t rom nomal Code handang ocda
hom'
enon handln (Bde om man
ne 4d prpgram). and un
ehanes ruadalLRtu
t samulals
ennos handlrng takes pial at ouG
manncr.
t makes or cean ObAt
tault toleant paogram.
alsla4 Soma comB nexannpluk
handling:
dikde
2.Accesstng te elenls
Jeyond th ange
3. fnvalrd tnpua
h hand disk CHash
S.
optnga non - eatent lule
b huap moneu exhauked
Exteplfonal havding ual
Jay handeng anomalo
knouón has
buneiceptd
Exepli
eMOY hat
ondl handlhng.
dustng un ttma o Colled
Exupson.
(od. th at mégt hae
an extep ion thioon tn fl
ColLed ay block
The pAOL SS by wht chi an
etepBon G qennat d and passed
to te phogAam 6 called
HnsoLon na 9Ãstng an enor.
Caphudng anoused th at
exapionon exlsutng
hàs qULst
Statrnet tnat t s to sesolva
te psoblum A a calad Catcag
The JHok code Hhat atemßt
to deal otth erapion
(aed Ex cept Claue
Etupi orn block (or) atch olock
’8eq ene d, method Cals that
to te
pont the exaphor
OcUd t called btack thae.
The delaut etupiton handlur
4, an etuplHon.
psauta oud. e1cephon dusotptor
4.psarta he stack thae (1e htnanch
meknods
3 CausL ne phoqrarm to esnanade.
kesMnale
when to Use ete plton handrng:
The ciepion handtng a tdaal
fox
pAOLSsing cuptonal shuaikon
a.paousst ng e uptiors tor. (ompouLv
nat cannot hadle them dtsucl
3 aqe puo eus th at suqutra
HADY pAOLssing.
NoTE:
wnhandd. aapio l cause
Pyth on to hat ettrption.eluio n.
Suwday:
esLLLpte # Wte hoe te Lode that
may qennate an upkon
clssMate
Date
Page

exapt: Code hene about wh


# WAi
to do wen exepi on OCUed.
eg: y:
et ept:

'drvde bs ZeaD
X= fut(xi)
eupt : )

en10Y

lsla4
Ok fale
whele not ok:

humbosbng =
Autegey
10pu
put C"enter
n= 1nt (numbarsbng
Ok=Te
patnt-(nylck.
TeadC)
A.tut
EnlnteITupt
o keyboaid
EnDr key Eor, OVeo
EroY Dision Zto Erroi, yalue Eno1, upe
ErD,Impot
Enc Index EnroY Name
Eno Output pt In EorL io
rynorJ ile Es1DrEnd
the q EOF
e0 an
tnteqer an
ewter O
utege erorNOta
Valid
fopl fnteqexY Oehter
aD
r Valtd aaNot ConD pavt
etupt
pale
claseate
qlsl an2k
Setond Aqumtut d, tu cxupt
block

t co de
Exept <eiceptfonnae >as< exarqune
t handleeror hane i

u 8
Psaut (UYes ut 1", CDls ))
píwt ( reswt a C1o/0))

Psnt (Met upt10 n , Sy le))

eupton- diMston by zerD.

Handbng Dukple eriONS &


SUntax:
#:
elupt <el uptonname 1 >
#:
exapt < acepionnamea:
to no exupkon then
Hne statuments In Uas block ad
eteusted
fa:
clasSMte
Date
Page

Pnoqramto ount no. d lon da


endíng th t&T
de Couvt oDadsl):
Lh Dpen (Vabc-txt") as f:
for Irne n fi
for Loord in. tne spltt ():
t= len (oord)
If (oord[i-1]=Tor) ooTd [i-]
pat Cod, Janlwod))
pravt "otal word endrng oith ' Qe',
(ountDYdsl)
Q. Count total no.d uppucau, koaeu ta

open
dota f Suad (
Cnt Ucase =0
CntlOK =D
Cntdsgts =D
for ch in dota :
ch ahoAg l):
Cnt Jiow tul

Cnt dgtb t=l


Dste

piit
DAt(Total no- d Léaklateyaxe', (cntIcase

oPsa bouat a ta pot wlurch las


penstve
uqit b
tutal d endmg atth t ae 1L
Pot 3
total a0d endong otth
alsSAte
oate
Page

d Couat toods):

soy laDd In Jines split ):

ptnt ( kot al Loods ", w

qcup c cootds maks Sntchce.

pt append dao!")
-feateda ode = ht Cinpt ( Entor Heplaue a
ak) Phame= fnput ("Enter he plauer ronm
Rcore =TE Iinput 'entcr the mdHdun au
ronk= Tunt (rnput (U Ento the player ant
9uC = Ptode ": Pcode" Pnang":Pnome, 'soe

fsakto) Prctle.dump (a, f)


dpcle-ard) f close
prt)biappord )
abt &wbt 04
Dafe

(ode to Couvt sa(oxd Tn br nasu


nport prckle
del CountgutordAD:
f= open (na iks-dat

doda = Prckle. Ioad ()


kafoy SIn data:
Rnd one-onROrd Cnt t=la
eicept Elupipn

pavnt (hta zle has' cnt,

@fmpoft prckle
de, an adrcA ():
d= 4toool': ' sulbhamAhmedaad
lucooo': CBhavn, Anand,
Coos': ['ontyBorodo'
Takionelr hckle. dump,f)
ib binauyf-tloxL)
brrtuy d =Prckle load Ct)
Te
f(loc
blnadscl)
clssate
Date
Page

4'CoooiISubham mumbat', Cood.


Chhain,chenni], 'tooo 3: 'lahlA,
baordo!74.
Tmpot prck lefun Nae
Stauch de,(Keasch-95 plua():
record
From
bnay
4: open (Mmavks--dnt "ab+)
Yn = nt lin put ("euter Hha adl no :"))
Snang= mput (Metr the name!)
matks =1nt InnputlMentey te movks :"))

oppendd Tet. appnd Cdatn


Prckle dump Lrec. f)
Ch= Tnput ("add more retDrds?Yes; )
f, Ch.Joser (=lyus'
byeak.
f cloe )
zOpn ( matks. dat | Myb")
Cnt=D
by

for san
dola:

PCnt ("sOrd,Lnt)
cdassnate
Dote
Puge

prínt fraks sí1)


Starad Straa ELupton :
Seanch qs Þlus ()

fmpoft Prckle
de, add_ecord [):
fle =Dpenl" employe .dat", "ab")
Lohele T e
Gmp ={3
Cmp =['empiode'l=Tt Cinput ["Entzrcmplayuind
)
CmpL'name'J=Input ("Entu emplbya name "
Cmpl'sauauy=t (input ("Entu the salaus:"))
prckle -dump (emp, Frle)
Ch=inputC "Do youLAnt to add more uDAdA!)

break
ftle-clox l)
Rle =open ("emplayc. .dat'" " yb")

Cmp= prckle. load CFLL)


4emp 'Sala8s'J 3ooo0:
prine (emp)
upk EofEroy) ’Vacan 4enzakker
Pa sS Pa Lon) sla z nt..
add ecord C
Seanch ()
Dete

impott sy
f=Dpen (Emploge. cSV,'a',uolor.=
emplosttu = (SV- 1o8th CE. dedrmitey =

CempHc = [l'ion1'An 'A Sto1,


['io0s, Sensat', '& ba10]
['10oul, Pamod 'gsooo
cloel).
Rending utOnd.
fmpotk CsV
Ssuader = GV. puader(h
tor rec tn Sreader:
prive(rec)
Read tovteut as frto drcionos obtet

dota = (sy. bI Raderlogen (Mstudets. CsV)


for 10 In data:
pdvavd (rouo)
Aalao24stack.

L3te a pHogiam pror stack.


C= y
PArt ("-PpsH)\n"
Patnt ( 2- Pop\n)
PrE (3-D1sPLAY\n"
Ch= tut (tnput ('enter ur chote!))
14 CCh==): enter elument
d=tnput (ete ttr tot))
St-append ld)
st==[1:
PsTt (empy stak!)
cbe:
Psant ("ddeted elemat TaSt.pop()
eh (h==):
fbrT In Yange lenlst) -l, -1,-0:
Ptvt (st()
elr lch=s4):
otedk exit
C= fnput (do b want to tonkinue(yin")
Seauch(S,d) aU
bn =
Pos
34,48,1oJ S=3,n,
A5,
hehun
=wrd- Jast
[medJ: Jrst key< elr
CmId: st >kay ln
ud ubusn
lastl a (trst+ =td
ltrst<=last
J: Loltle
(ast) Aan last=
=o
tst
kuy): (tst, Stauch asy bndel
[euch bfn pHOgTam
to a lt L3
d). Cl, Seogch
adh leelument
to (Muntu tltnput Tn d-
9083,I1,4S, 1l=19,14,
3, 15,
nda l'seadhed Aehn
Prut
Valu tYcuuvs
he heauál
layr): (lan sange in Îtor
):(ax, Stach del,
Seauch Jtneay fPAogYam
or SendingwArtae
MAte Date
slal4 Áontng
|. Jote a program for bubbe sorti
del bue- Sort lust):
n= len Ast)
byorforP m
(allonzOVte Hange (n):
btn Yanqe (o, n -i-1):
af ist Li]> Irst [141]:
Itst GJ Irst [^i ]=lrslj til, stJ
PEt (tst)
Irst = Ls, , 3,l,, 4J
bubble - sort (Irst).

0/P -9, 1,4, t, 8, 13J.

You might also like