You are on page 1of 6

1.

adhithya
2. amrish
3. anantha
4. cherishma
5. darun
6. nitesh
7. pradeesh
8. pranetha
9. magdaleen
10. ritessh
11. sakethepriya
12. sanjita
13. sanjiv
14. shreya
15. sreevas
16. abirami
17.adithya
18. tarika
19. mritunjay
20. sreekumarn
21. seetha
22. vidyalakshmi
23. raja
24. aadhavan
25. jothis kavin
26. arriya parthiban
27. pradeesh
28. arya
29. kavin
30.

flow of execution

1def addition(a,b):
2 c=a+b
3 print('c value=',c)
4a=10
5b=20
6addition(a,b)/

flow of execution
1=>4=>5=> 6=>1=>2=>3

2. write a python function to find the factorial value.

1def findfact(n):
2 fact=1
3 for i in range(1,n+1):
4 fact=fact*i
5 print("factorial value=",fact)
6n=int(input("enter n value"))
7findfact(n)
8print("hello")(
flow of execution
1=> 6=> 7=> 1=>2=> 3=> 4=>5=> 8

flow of execution => with for loop


2. task
1def increment(x):
2 z=45
3 x=x+1
4 print(x)
5y=3
6print(y)
7increment(y)
8print(y)
9q=77
10print(q)
11increment(q)
12print(q)
flow of execution
1=> 5=> 6=> 7=> 1=>2=>3=>4=>8
=>9=> 10=> 11=> 1=>2=>3=>4=>12

passing parameters
python supports three type of formal arugment /parametes.
1. positional arguments
2. default arguments
3. keyword or named arguments

positional arguements /parameters


=> when function call statement must match the number and
order of arguments as defined in the function
definition, this is called positional argument matching
example
def addition(a,b): ## no of argument -2
c=a+b
print("c value=",c)
a=10
b=20
addition(a,b) ## no of argument 2 positional a,b

note :
positional arugement => found in => function defintion,
function calling
a argument with out = symbol known positional argument

a,b are the positional argument

example2
def findinterest(p,n,r):
si=p*n*r/100
print(si)
si=5000
n=5
r=2
findinterest(p,n,r)

question is
what are the positional argument in
function calling findinterst(p,n,r)
ans)
p,n,r are positional argument

Default arguments
=> A parameter having default value in
the function header is known as default
parameter.

default parameter : found in function header only

solution:
def addition(a,b=0):
c=a+b
print("c vlaue=",c)
a=10
b=20
addition(a,b)
addition(a)
"""
function header
def addition(a,b=0):
postional:a
default: b

"""

example 3:
def findinterest(p,n=5,r=2):
si=p*n*r/100
print(si)
p=5000
n=5
r=2
findinterest(p,n,r)
findinterst(p,n)
findinterst(p)
"""
find positional and default
postional : p
default :n,r

"""

example 4
find the output
def findinterest(p,n=5,r=2):
si=p*n*r//100
print(si)
p=5000
n=5
r=2
findinterest(p,n,r)
findinterst(p,n)
findinterst(p)
calc p=5000 n=5 r=2
findinterest(p,n,r)=> 5000*5*2//100 => 500
findintest(p,n) => p=500 n=5 r=2 => 500
findinterest(p) => p=500 n=5 r=2 => 500
output
500
500
500

example 5
def findinterest(p,n=3,r=1):
si=p*n*r//100
print(si)
p=3000
n=5
r=2
findinterest(p,n,r)
findinterst(p,n) ## missing r
findinterst(p) ## mising n,r
calc
findinterest(p,n,r) p=3000 n=5 r=2
si=3000*5*2//100=> 300
findinterest(p,n,r) => p=300n=5 r=1
si=3000*5*1//100 => 150
findinteest(p) => p=3000 n=3 r=1
3000*3*1//100 => 90

named argument =>


19. sreekumaran
20. s

You might also like