et flncion Ls a named aa ahd
ram St.
functions make 0.
and. undustandabte. ~ tp
raat
Q Proprammnan. by
MOOLAM nan ag runt earers
ae|
- Udectonding fundins
- | Yoce have worked with potynemials tn. Ma [te mates
E Ex), f (x)= t
E | f Gi) =2 a
Fa)- 8, 5 ts
he notation pet = ae can
nection)
timely fy ik ale
| arguement Ct, value given to ib and =
BZ | Boc® 46 hh —Panctionaliy t: Pag see Peeaa ee
jfenfonms
E [You can extn — dina program, that
Lb | Com have Onpucemente Coates Gginen to ity,
TF needed -
a) cCoan_f cextain pty bo heme ee.
E en fs AN
can sulin a ed
{ yf
Ch
E it
Ev def calc Something OY:
r=2*x**2 | _
return ff 1 Tr |
ft Ss t
= int (input (“Enter ano.")) | (
rate ( £gleSometiing (a)) }dunipian follwing def is ths na
| dhe func. foe heat function _name_ig
gour niud do aka - amc
frotimnt in bython. De takin. ie
oT srame > valuas A6be- passed oareT
ee ee
Python coms folraded with many ae .
| Buift wn Funetioms + These aco
L_ (| TT
\avaclalrte
HPoagra mame yor< cam cal ybtor
| S2efining Functions fet Lyihan—
PYTHON FUNCTION “TyPES
ruliens that
Safina - you aon use PAGE
free —alefinecl ed anh are ahuways
Aen L_, type U, dita) Bons
Functions clefined iea_ 1 Modules:
, TO _use_Ain ()_,
‘User defined Funckions :
Dhase 211 defined dy se pa
|
nelions can Le. theghel. as lees
funds a program. 8 hpns _
def sum (x,y)! L ee -
S=x+y a SS —
return S$ SoK a‘ real noma
[RS gee greet an”
7 a Good_ aa Momings)
wo ape ra:
Function ,
Header *
~ Parameter Voninioles that ave. set. bitted —usithin the pore,
_ tm. the func Headep sn srs sSooe ssh 33.57
mote Ateck of. stat
Body +. benvath
Indenjut;
Genfut in Aan Hpac fi = ee . os
me) 22, hh
Atk ee : oe si j
fae same incon Gohan ame beckdef _ sum (n)
S=mn*¥1 +n*2
ff sum of 3 Multiples
er
retum $§ =
def sum (n)
sx'n® J ton? 2s oat.
priat ‘a
ft tructure nure oF PERRET Poni
|
[ ents _in Prapren YOBKAR) , all pune”
ae it Pie be she top fatiewrd
‘pilignt Ase
tons Phase salt
Foe.
th no _indintalien) -
—
pth ats
To Pythen anlar freler storll the executtorr of
fe pp from the top Aue statement
The “top- Aevel statment art part of the
bones program i teen ey Py then giver te
le j to top Ivi statements asprint ("Hi there | T'm Ansa")
«
| print_(“At the top -mest (Qhk Dow |
——Outeyt:
—: At thetop - mast level right raw.
a ~Inside main Bay ahr,
: Execution in a fan
+ . ee
hia fh ke ate a stack aiaAn execution Ponies contain ra
dome intinat infer. at fo ebegging):
;Meme OF the ess ott
Values passe to o funcrina| Ntsoa “ge x +y-
____return_S
- Vous Float. (input Genie: first no. ”)
_ mum 2 float ( (input_("“Enter Second no-"
_\sume = sum2 (numt, -num2)
iprint_("\Sum_of the ‘tla
Note: _ Athen. tant wading prem. hited down,
But _dtatimunt are ‘
Tin fom eect. One at a Him,
> The. functiem ian
the ‘caller’. The.
‘called func” “Cor diesDefoutt A Legucemcnle ance us efit im selecations
| arene some Pdrametirt have the Bare value -
[“* hey provide flexibetity do_the pugrammes
“Advantages. of default parameters ;
They canbe used
A 90
add, sub, mult, div, mod =_
print_ (' Sum_oF given_no- we ada)
___print ("Difference __O£Given_no.-", sub)
_print(" Product —of “given “no." mult)
print" Division of given _no-", ol'v)
_print(" Modulo of given no-", mot) / -be U
| to ws an ex preted ge
fast
Langer cacao’ ga jab a ete
of dagen statement!
an auth melic- ax prestiored. ee oe
| greater (125) a24) )) ce _
logieat —-— ———
Qa ex foreizion. egy 3
test (a orb)
a func” “call (fun ecempattion) ef $$
int_(stre(52))
int_( float (" 52.5 ")* tt fae
int (str (ea) + steC10, so por!
4 ee lie eerie Seine larg ets: fume, ___
ACoOpe of Yartlix a
taper? Nedelsl
Ths 4 eo eles 1 int (input_(" enter Secor pe") —
= _2 Sum = Calc pe bei
jeune L" Aun —of gi nots Sum) a
if 7 OER,
Noteé | Global seule mitt 1d seemoved_ wn the
program ik over, a a
fi} Sosy — sti pee
def __ovg (oy)a A .
| sm= Cale Ody). =
retumn sm /2 S
Regd Un Creamy)
smum2> int | input (" afo. ayy 1
print (Avg. of these mo.” > 2V9 (mut num?)
>
|oui
I
LL.
}
|
1
|
Voruiatrtes _clepiriedh \eudtiele att function are
Global Variabur. _ - —
| PBI
ea = 6 = te
def func (a):
poe
a.
+ aS ge Y pete
LI — (abu ee _ — i -
eee
b= y+ func (x) se
— || — preint_¢2) —___________
is q = print (funety)) % As St st
Fly &_ x are slop series
for global Variables , lifetime is entre _progran
run (-e, v Hive ins mmgeng cy. as Leng Oe
the program fi soning f A _
for local varidstés_, it Uther fune”'s rur\ ee
a
ott pesdution | - 7
‘fe wey ne _aupeun a.
lee, you acelss
ia papa o
thon name “resolution —
oR
LEGB cule. ————
ule alta nam a
qt), ft checks within bee
es Lowt namespacs, AB. "fas varia
“with Ah same “name ,;if yes ,—Pythen_| ae |
ty value. a
Tf mot “then “it_mpves_ Ae step Da a
TZ
= Gil Python nen Chucks Hos Fraclosing “environ
(eg: 1] whether. vara ble —uxibh 2
- jtame name) ; if yer, Pythen uses 4h vost
— Ifthe vauiabte is net net_found hm Hh Cw}
penal Py then _Anpeali nis step 40
ghee Level scat environment, vB any
Th mot then 33 moves eS step 3
{ay fythen TOW Cheese, _ Ns
whether thong a the Gtobos environm!!
mame; if po Voualee with the 40m
7 US ib yale.
Lt net tem,
itn, 2
OMA 40 Akt 4,fonctions att um = built varialts and
net Ord. of Python if thou 41 @ ‘pasetadeee
-| wth the same mame, ee uses ite Valter _
__|_name eee :
4,
|| 1 i 15
amis not ji i
Al “dt reo chicks fee num 1 In Llobale: enueirdynent
def calc (x, ee rT
we =X +y
mara £ mw @ lobal
ret Gna) oro
lum 4_> int “Cinput_C!-Entin_No- 4") Pier Viren
num_2=_ int (input rr ra) oo
rint_("“Sum__is")- um 1, mum 2, Ys oy
ten rhb pout chuck. the decal Piviten mint
—_ i 1b enclosing eauiconment).- es
Pythen fol mum tt hert, A0- ik. picks aa visas
bl md foints__xt— er aa me
“det “greet OL - em
a ____— print - hello", name) __— =
_ “get er in Licata,
a So Coaricconrtt |
—Wanialle Anenuse a it an fe]
—-Omol _ mete (te catia § yoni
figers =
print Pier
State 17 )
print (gers)St
_ def state 1Q-:
__|| What ify you _ want “to_use global variable
inside local scope?
—|The_global _ Ataliment 7, a duclacahin ushich.
jtatde for the entire cwount cod _Lteck -
| mmedns that the Listed —rclunuiPiers are part
of tee ‘Hotes namuepacs pat envtrénment -
a ee
eI tigers _= 9. == =
p—t —print_(tigecs) = 7
Ll tgers = 95 ee ee
£ | print (t'9¢ p sa ot oe
LIistate 7 ¢) _ fe
|_ print _(+gecs) a
| _ a
E poured PRET
[les Pees -
| 5 7 a — a
Ls — ——__—— ——
fte:| The global statement Cannot be reuerted tn 2
F |e mn UAT» ent at usin wg _
E i al statement in dytoan proven: a 7
E | Athsugh global vou Cam be acc 1.
local A hut 4 GOOk_ pr,
ee de, bap Giisal aniltis goo a7
Vecal veulables toc.= _
~ I
|
det welewme (Js — a So
satin fount.
_- 1 Pecitional sats
- 2 Ofaubt argucmente Orpen TT neal Kiyssoid asp tminh
CApusemninds iy. Mariette Length|
te
- ipsa are the
ip peut (“Arca ol Carch = °, ax)
"s is Obs breuon as FORMAL ___
ARGUEMENTS a _
ti value that Lt passed to Abs
Ibn
[e when dt is alld. Sy ther wards,
(iraroke
AcTvAL PARAMETER» aS
import math ar cae
rea —— formes Cxgusmmenl
| a= math. pi. ST
retuun Q
}
2 ut tt alia bamuse at ACTUAL ARGUEMENT
i]
|
= int_ Capt Fuld Ze)
| on = ana [n) <— =e = E
| func Canale, any davasue Tree Vatuse
|, -_|| def 7 C
of vier 4 funchion isa fiunchr:
LL beiown _ any = vale or final yaks _
t eas, pelt be __
(314 wid fine” (Cacmutiost called nan -fruit fs
ee to the Calter. =
| oe F greet_C): een _— rn ae
& laz greet 0 _ —~ oo
OUTPUT: - _
None
|
a- int Cinhut (" Firter peimifal Interest yy i
int (input (" a tims") a er
. ate Se eee
seme action 6 AO _Aerme 90k Ant do net _
An_the cabin . —
\fumc)_re terns Aegat cong wads — ag Petia
_ print_(" Yo ")_ =
Lprint_(o) —
Yomig = infu bata tiny
On Cound vousls ( mtg)
feat "Tote vounte inf
| Enter Any String
|| Teter Vousely
in The g
»)
The quick bse Jo
Wuck bron fe au S$.a tl ee Conk + =f
—_retwen __ count Z.
mag = “put C Erlr_ ag)
| prune (4 etal vowel Tn! _, onde
| — Jumble (ate 1)
C2 Court
a nip impeait *F
_shr.2= — empty string.
hum IO pa
for tin range {Aun (sta 4) a
if aa ites ()
= Strd + sted [1]. @ upp
elif eo sade upp (Je
AM Q= str 2s sertli] Lowel)
ebif str Lie]. as cdigee (Qs |
J 2 = atrd + 0a
else
Mb 30 24 @!
relumn 3% 2- =e — Cbd any tring) ~
fy = Jumbe (mtg) — So
mares ( Tambtid —aaleg te mag)_______ele: i _
- _ dict (41
relim dict
[20 fast thedint record at Q dichienar
amo updah ther 2arkt _
Washer (anus AT
_ Atud [marks] *\P = - ae
Atud L" status") = "updated"
Letudent i= LRedt no
t _ —__£4_,—ehegpe of Variables
| Beate matans in wehibh “ on
i i at
A ram declaud np Mok segment (main)
4 heya tug py Hrawe. Ged Py, Sa
cain lated I entene foc pean 7
Mined ox duds ati
fancliing cre gletal
we.7 na dala ta fl” apd ae
ly rT bia hit
chewy | oad the otthes elec atuide” the fonchon
Lhe foeonal_fbaramelir!. ate.
a “o eee
[— a bs 2 ec re