1.fahrenheit To Celsius and Vice Versa Conversion
1.fahrenheit To Celsius and Vice Versa Conversion
1.Fahrenheit to Celsius
2.Celsius to Fahrenheit
3.Exit
___________________________________________________
Enter your choice:1
You are selected Fahrenheit to Celsius conversion
Enter a Fahrenheit value : 44
Celsius of 44.0 in Fahrenheit is 6.666666666666667
___________________________________________________
Enter your choice:2
You are selected Celsius to Fahrenheit conversion
Enter a Celsius value : 6.666666666666667
Fahrenheit of 6.666666666666667 in Celsius is 44.0
__________________________________________________
Enter your choice:3
Exiting............
Thank you
2.GEOMETRIC FIGURES
while True:
print(" 1: Area of Rectangle")
print(" 2: Area of square")
print(" 3: Area of circle")
print(" 4: Area of triangle")
print(" 5: Exit")
c=int(input("Enter your choice:"))
print("______________")
def rect():
print("To find area of rectangle")
l=int(input("Enter a length of rectangle:"))
w=int(input("Enter a width of rectangle:"))
print("Area of rectangle is:",(l*w))
def squ():
print("To find area of square")
side=int(input("Enter a side of square in cm"))
print("Area of square is:",(side*side))
def cir():
print("To find area of circle")
r=int(input("Enter radius of circle:"))
print("Area of circle(22/7)",(3.14*r*r))
def tri():
print("To find area of triangle")
a=int(input("Enter length of triangle:"))
b=int(input("Enter breadth of triangle:"))
c=int(input("Enter height of triangle:"))
s=(a+b+c)/2
area=(s*(s-a)*(s-b)*(s-c))**0.5
print("Area of triangle is:",area)
if(c==1):
rect()
elif(c==2):
squ()
elif(c==3):
cir()
elif(c==4):
tri()
elif(c==5):
print('Thank you')
else:
print("Invalid option")
c=input("press Enter(y)to continue")
OUTPUT :
1.area of rectangle
2.area of square
3.area of circle
4.area of triangle
5.Exit
Enter your choice:1
___________________________
To find area of rectangle..
Enter a length of rectangle : 2
Enter a width of rectangle:3
area of rectangle is : 6
1.area of rectangle
2.area of square
3.area of circle
4.area of triangle
5.Exit
Enter your choice:5
___________________________
Thank you.
3.FIBONACCI SERIES
print ("Fibonacci Series")
print ("================")
n=int (input("Enter the Number of terms:"))
f=0
s=1
sum=0
for i in range(0,n):
if i<=1:
sum=i
print(sum)
else:
sum=f+s
f=s
s=sum
print(sum)
OUTPUT :
How many terms ? 5
Fibonacci sequence:
0
1
1
2
3
4.FACTORIAL CALCULATION
print("Factroial Calculation")
num=int(input("Enter the number:"))
fact=1
if num<0:
print("Negative number")
elif num==0:
print("The factorial of 0 is 1")
elif num>0:
for i in range(1,num+1):
fact=fact*i
print("The factorial of",num,"is",fact)
OUTPUT :
import math
n=int(input("enter a value for n:"))
sum=0
for i in range(1,n+1):
sum=sum+pow(-1,i-1)*i/math.factorial(i)
print(sum)
OUTPUT :
A=[[1,2,3],[2,3,4],[2,3,4]]
B=[[1,3,2],[6,3,7],[3,4,5]]
sum = [[0,0,0],
[0,0,0],
[0,0,0]]
product = [[0,0,0],
[0,0,0],
[0,0,0]]
if len(A[0])!=len(B):
print("Matrix is not compatible for product")
else:
for i in range(len(A)):
for j in range(len(A[0])):
sum[i][j]=A[i][j] + B[i][j]
print("\n\nsum of a matrix is:")
for r in sum:
print(r)
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
product[i][j]+=A[i][k]*B[k][j]
print("\n\n product of a matrix is")
for r in product:
print(r)
OUTPUT:
product of a matrix is
[22, 21, 31]
[32, 31, 45]
[32, 31, 45]
7. EXPLORING STRING FUNCTIONS
while True:
print(""" 1.To convert your string into uppercase
2.To convert your string into lowercase
3.To check if it is in upper
4.To check if it is in lower
5.To join two strings
6.To print a substring from a string
7.Exit""")
i=int(input("Enter your choice"))
if(i=='1'):
s=int(input("Enter a string"))
print(str.upper(s))
elif(i=='2'):
s=int(input("Enter a string"))
print(str.lower(s))
elif(i=='3'):
s=int(input("Enter a string"))
print(str.isupper(s))
elif(i=='4'):
s=int(input("Enter a string"))
print(str.islower(s))
elif(i=='5'):
s=int(input("Enter a string"))
s1=int(input("Enter a string"))
print(s+s1)
elif(i=='6'):
s=int(input("Enter a string:"))
n1=int(input("enter your starting index value:"))
n2=int(input("enter your next value of ending index value:"))
print(s[n1:n2])
elif(i=='7'):
print("Thankyou")
exit()
else:
print("invalid operation")
OUTPUT :
file=open("file.txt","w")
text=input("Enter any text to write in existing file:")
file.write(text)
file=open("file.txt","r")
print("Reading from existing file.....")
print(file.read())
OUTPUT :
import turtle as t
while(True):
t.shape("turtle")
t.speed(1)
t.bgcolor("orange")
t.circle(100)
OUTPUT :