Ch-3 Working With Functions
Ch-3 Working With Functions
21
Date
Functiohs'ti
Functioht
Easy opdototiogb
Tupes cf Eonctiohs' o
Int cli23.45)
123
DOMS Page No.
Date
flact C123-4S)
123-4S
tapeCl
of
This unetioh retsuny the dto ype
Orgument.
Eg ee Clo)
Class int
3OMS Page No. 2.3
Date
bl
pint(a,b)
hs int Cinpt(" Eiexh
Uesdag
tineieh
Write a funtioh in
the ho, of
and dispoy
lawecae.
def F
S= inpt(Erter StYíng
ftr n
ifi.
if i,isup per)
else:
|= 4 1
pint C" 1otal ho, of upper cose leiie s
prin Total ho. of IoleYcase letters is
Random Hodole.
To Kond om functíon inpt a libraty robe
as Yondom.
\ondomCli Tt aenetes
aeneratej olye
alye from0 tol.
pichs tan dom Volle Uhich is qteaterthan
eajual to 0 but less than l.
DO15 Page No. 2S
Date
Fidag
Usey Funcion
betined
satemens
Example
Ldefiforitbt
no = int CinptcExtev h o : ) . d i
for i in Yange Cno, Q,):
iad fact= fat *i
t ' h prít C f á c i ) c ig o t i
printC)
(Jmto, 10)
dshs
volye
tlax
def -functish C) :
Stotement
retun value
pirt (Eunclloh C)
print (a)
92
for i in Iange
S=Sti
Yetun S
ptint CfCo)
DOMS
Date Pags No.
print CP)
Exompe
def s Ca,b)
teturn Cc)
I= Iht Cinput C" Enter: " )
s= 1ntcinput (" Erter: 1))
print (P)
DOMSPage No. 24
Date
return
f=SCO
Scope of Voriable
def fc):
prml Cx)
print (x)
Local Scop
A Local Variabe Is Voiable defihe Gthih a
carnst be
fundioh,e cannst be accessed
accessed otside he fuclia
Date Page No. 0
print Co)
printcc) ne
Ghloal Voable
KabgId Aauber
Oefarlt Axaumcht
deff Cx2E330):
priht(p)i
Welnedy
Keuuord Aaubent
Adyortages
5Ucina the fUNioh ith heacd atqomenti
ROS0eras e do hot to emenberhe
Otder cf he aroument.
default
Lhich Luart to Qs olhers have
aYgurert alues.
DOMS Page No. 3
Date
St
pint ( s ) b e
Surm (36)
print (o)
pxint (a)
DOMS
Date Page No. U
fohction
assiha ist to a
def fi):
for i in tahqe(0,lenC):
prikt c)
1=eal CippC"Enler list:" ) ) i a
priht ci1)
Ditiahatq o a fhciioh
Posita
Keas ole immuhable, Values ote hulable.
def cd):
-for i in d
prirt&
Ca)
dl= eval Cinpt"Enler the Dictiohang: ))
prit Ca)
pitCa)
DOM5Page No. S
Date
slelze
def f Csting):
fox i in sitihg:
def c):
foy i in t:
pint Cs)
A= eval Cinpt C"Enter 1ople Elemenls "))
Nestcd Funcioh
defiCab):
pikt ("a-", a, "'b-", b)
def Sumlacb)
pist Cat b)
def sob Ca,b)
pxrikt (a-b)
Sum CI0,4)
sub (10,4)
fCio, 4)
DOMS Page No. 34
Date
def hello):
prit " Hello" WorAM)
def maih :
pit (This is the main forctior)
helo)
maihC)
heqtuotd
Global 4he
fonction allots
iatside furclon fsrdias
Frut
Di{feentigte Pprit
CCnol) ho=
Use Explairthe Fonctiohtelorn Ngn- defcn he
qloba ful int
lool ot Fruitful Iht Cn)lpE
oihIoCpCo3)
hae XE st ihitnum
is 1he Lith functión Cinput Estr(n)
value, qlobal
cortext,
heby A
proatom betcGECh C"
he fehloh vale
Ouide fondich Enter
defaulH
is
ittenhction is eywgId.h
hnguad Inhelp Fxitfel The
mer trfcl of
fohcioh :)
he variabledec to ot The lenc)): ht
local sultable
rcioh,ibside
USuse fonttioh fohchs humb
\hsidealobalby Puthon,
hat
vorableaalobul example
alobal the laied Date
DOMS
Global
Keyuatd ho letutn and
defauh. ke
keqLwodfuhction decihslde a do hoh-ftut Pagp
No. 3
Voioble a
kte. aia hot
ho to olue
u