1. def main():
print('enter the option')
print('1: celsius to fahrenheit')
print('2: fahrenheit to celsius')
o=int(input('emter the option'))
if(o==1):
c=float(input('emter celsius'))
f=float((9.0/5.0))*c+32
print('fharenheit',f)
else:
f=float(input('enter fharenheit'))
c=float(5.0/9.0)*(f-32.0)
print('celsius',c)
if __name__=='__main__':
main()
1.TEMPERATURE CONVERSION
Print Function & Input Function
Fahrenheit Declared Function
Fahrenheit Declared Function
if…else function
Call Main Funtion
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
2. def areasquare(a):
area=a*a
return(area)
def arearectangle(l,b):
a=l*b
return(a)
def areacircle(r):
import math
a1=math.pi*r*r
return(a1)
def areatriangle(b,h):
a2=float(0.5*b*h)
return(a2)
def main():
print('enter your option')
print('1. enter area of square')
print('2. enter area of rectangle')
print('3. enter area of circle')
print('4. enter area of triangle')
1 2
2.AREA OF THE SHAPES
Square
Rectangle
Circle
Triangle
Print Function
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
3. o=int(input('enter your option'))
if(o==1):
a=int(input('enter area'))
x=areasquare(a)
print('area of square',x)
elif(o==2):
l1=int(input('enter length'))
b1=int(input('enter breath'))
y=arearectangle(l1,b1)
print('area of rectangel',y)
elif(o==3):
r=int(input('enter a circle'))
z=areacircle(r)
print('area of circle',z)
elif(o==4):
b1=int(input('enter the breath'))
h1=float(input('enter the heigth'))
aa=areatriangle(b1,h1)
print('area of triangle',aa)
if __name__=='__main__':
main()
3 4
2. AREA OF THE SHAPES
Square
Rectangle
Circle
Triangle
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
4. def main():
print('enter the marks')
m1=float(input('tamil'))
m2=float(input('english'))
m3=float(input('computer'))
t=m1+m2+m3
p=(t/300)*100
print('mark obtained in tamil',m1)
print('mark obtained in english',m2)
print('mark obtained in computer',m3)
print('total marks in 3 subjects',t)
print('percentage',p)
if(p>=80):
print('grade A')
elif(p>70 and p<80):
print('grade B')
elif(p>60 and p<70):
print('grade C')
elif(p>40 and p<60):
print('grade d')
elif(p<40):
print('grade E')
if __name__=='__main__':
main()
3. PERCENTAGE
Print & Marks
Print
Grade A
Grade B
Grade C
Grade D
Grade E
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
5. def main():
print('fibonacci series')
n=int(input('enter the range'))
a=1
b=2
print(a)
print(b)
for i in range(n+1):
c=a+b
print(c)
a=b
b=c
if __name__=='__main__':
main()
4. FIBONACCI SERIES
Print & Declare
Print Range
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
6. def main():
n=int(input('enter the factorial of number:'))
fact=1
for i in range(1,n+1):
fact=fact*1
print('factorial of the number %d is %d',(n,fact))
if __name__=='__main__':
main()
5. FACTORIAL PROGRAM
Input
Print range
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
7. def facto(n):
fact=1
for i in range(1,n+1):
fact=fact*i
return fact
def main():
n=int(input('enter the value'))
sum=0.0
for i in range(1,n+1):
if(i%2==0):
sum=float(sum)-float(i)/float(facto(i))
else:
sum=float(sum)+float(i)/float(facto(i))
print('sum of the series',round(sum,3))
if __name__=='__main__':
main()
6. SUM OF SERIES
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
Range
Sum
if
else
8. import matplotlib.pyplot as plt
def plothistogram(data):
plt.hist(data)
plt.xlabel('value')
plt.ylabel('Frequency')
plt.title('histogram')
plt.xlim(min(data)-1,max(data)+1)
plt.show()
def main():
data=eval(input('enter data to be plotted as histogram:'))
plothistogram(data)
if __name__=='__main__':
main()
7. HISTOGRAM
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
Package
Value & Limed
Print
9. import matplotlib.pyplot as plt
import math
def sinecurve():
plt.subplot(2,1,1)
degrees=range(0,360+1)
sinevalues=[math.sin(math.radians (i))for i in degrees]
plt.plot(sinevalues)
plt.xlabel('degrees')
plt.ylabel('sine value')
plt.title('sine curve')
plt.grid()
8. SINE AND COSINE
Mr. V. VEERANAN, M.Sc. Computer Science., Dip.in.Yoga.,
Package
Sine