Professional Documents
Culture Documents
C
C
1. darshan
2.blessy => 11th
3. josheph
4. cherimsh
5.parswanthan
6. seetha
functions
=> function is a subprogram that acts on a data
and it returns value.
syntax
def functionname(arg1,arg2,arg3):
statement1
statement2
note:
function defintion
def functionname(arg1,arg2,arg3): #function header
statement1 ----|
statement2 -----| body of statement
note:
def => keyword. it indicates function starts
function name => one of the identifiers
arg1,arg2,arg3=> necessity variable
solution:
def addition(a,b):
c=a+b
print("c value=",c)
##function ends here
##main() function starts here
a=10
b=20
addition(a,b)
example
def addition(a,b): ## function header
c=a+b
print("c value=",c)
##function ends here
##main() function starts here
a=10
b=20
addition(a,b) ## function calling
p=50
q=30
addition(p,q)
addition(60,70)
"""
c value= 30
c value= 80
c value= 130
"""
output
def addition(a,b): ## function header
c=a+b
print("c value=",c)
a=10
b=20
c=30
addition(a) ## function def 2 arg mismatch
addition(a,b,c)## function def 2 arg mismatch with 3 arg
"""
solution:
def swap(a,b):
a,b=b,a
print("a =",a,"b=",b)
a=10
b=20
swap(a,b)
output
a = 20 b= 10
solution:
n=int(input("enter n value"))
sum=0
for i in range(1,n+1):
sum=sum+i
print("sum value=",sum)