You are on page 1of 5

1.

arthisri
2. vidhya lakshmi
3. harish
4. pranetha
5. sanjitha
6.. arya
7. kavin

functions
=> same set of statemwent will repeat in diff times using
functions.
function syntax
function definition
def functionname(arg1,arg2,arg3):
statement1
statement2

note
def functionname(arg1,arg2,arg3): ## function header
statement1 ----}
statement2 -------}body of function
def => keyword
functioname => identifier
arg1,arg2,arg3 => necessity variable

1. write python program to find the addition of two values using


funciton.
functionname : addition()
argument : a,b

solution:

def addition(a,b):
c=a+b
print("c value=",c)
a=10
b=20
addition(a,b) ##funcitno calling
p=50
q=30
addition(p,q)

"""
c value= 30
c value= 80
"""

2. write a python program to find the simple interest


si=p*n*r/100
function name:findinterest()
arg: p,n,r
solution:
def findinterest(p,n,r):
si=p*n*r/100
print("simple interest=",si)

p=int(input("enter the principle"))


n=int(input("enter the no of year"))
r=int(input('enter the rate of interest'))
findinterest(p,n,r)
p=3000
n=3
r=2
findinterest(p,n,r)
"""
enter the principle5000
enter the no of year2
enter the rate of interest3
simple interest= 300.0
"""

3)write a python program to find the celcius value using


faranheit using function
c=(f-32)*5/9
functionname:findcelcius()
argument:f
solution:
def findcelcius(f):
c=(f-32)*5/9
print("c value=",c)
f=int(input("enter f value"))
findcelcius(f)

function with for loop


4) write a python program to find the following sum of series.
1+2+3+......n
n=> input argument
functionname:sumseries()
solution:
def sumseries(n):
sum=0
for i in range(1,n+1):
sum=sum+i
print("sum value=",sum)
n=int(input('enter n value'))
sumseries(n)

5, write a python program to find the following series.


1^1+2^2+3^3+.....n
using function.
function name:sumseries()
arg:n

solution:
def sumseries(n):
sum=0
for i in range(1,n+1):
sum=sum+i**i
print("sum value=",sum)
n=int(input('enter n value"))
sumsereies(n)

6)write a python function sumseries() to find the


sum of the following series.
1x+2x+3x+............nx
solution:
def sumseries(n,x):
sum=0
for i in range(1,n+1):
sum=sum+i*x
print("sum value=",sum)
n=int(input("enter n value"))
x=int(input("enter x value"))
sumseries(n,x)

7) write a python function sumseries()


to find the following series
1x^1+2x^2+3x^3+......nx^n
solution:
def sumseries(n,x):
sum=0
for i in range(1,n+1):
sum=sum+i*x**i
print("sum of series",sum)
n=int(input('enter n value'))
x=int(input('enter x value'))
sumseries(n,x)

You might also like