CS ch-2
CS ch-2
Ch-2
Hser Defined Function in Bython
FunctionA funetiovn is a'Sub Progra m thot
COm be
anonedi uut of a
gau frarom statements and it.
Tis uut othe
Rort tte kroyom The oast ineAntaut
reasom
homdlisg eaieri a ioly a mall
tho Brogom isded witlata tim
Anote reasonito aseuntign is to
Yeduee hnogromga
Functis mose a pvogr9m Yeadable
amo wndestonolabletoat piog na m mad
Aerebg mabing pnagram mamage neuk
Syntax det fumction- name largumeata)
Statement
Ex
=2* 2**2
2) det Qbe U:
print ('Hello)
Caling/Irsaking
To Haat hoo besm
defined eorlier yau meacd te conite
a fnetim call
be invaeed olld
folloiae., tby int
oargumuts sehorated by Comm as
retongk:))
b nt (inut ( Eate breodth recdayla)
Entu bresdlh
Entu brsdh etengla t
Area rectongle s: 200
det qreatee ky2):
elset
hyiatlz)' is qratea )
X
22
uthut 1st
(.)AP for odd ov eVeM
hait ('evem)
else
matiralmo (on)
hyiut lm Sum,Sum
)
|2 3
det Loble ca)
for b
heiat ( a * , , = ' , arb)
Heo Wo.
mO. s! )
(Toble
Toble (a)
for Su odo
Dtut Eutera
Sum = 26
WAP for Factoria ot Givem mo.
det fact ():
fat
for a (ne,-)
hriat n e , foct)
fact (m)
Etee a
6!= 120
oie (aSM)
a:n i t i u (Eutes
t a
natu nal )
Qutut 10
12 3 6 6 7 8 9
Sum 65
Sum O
Sumt
Qt 2
Sum
Sum 20
QWAP to fiual Table of
>>det Tablen)
iut CisAut('Ente
Table (n)
Table ot 6
6 30
36
10
oAP to fiuo foctovial giveu
a stve
def taet (n)
mul =I
Loile (n >o)!
Outu Ente
Fctorial = |20
nested If
foy (0,a):
hriat (
hrint )
2.
3
|2 3
det notri 2
for a (O,5):
hriut ()
22 2
3313
def Rehetri ):
for
for b
hrint a, end= )
hriat ()
Rela t
3
6
de coumt- tri
tor
foyb
hriut (sum, en - )
Cat tri)
# Retuasly Valuetrou Function
det
steteuut
amme avguwts)
Syta Ye tuvn value
add = Sum Q, b)
Gdd