0% found this document useful (0 votes)
30 views

1.fahrenheit To Celsius and Vice Versa Conversion

Uploaded by

abdul.king1810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

1.fahrenheit To Celsius and Vice Versa Conversion

Uploaded by

abdul.king1810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

FAHRENHEIT TO CELSIUS AND VICE VERSA


CONVERSION
while True:
print("Menu")
print(" 1: Celsius to Fahrenheit conversion")
print(" 2: Fahrenheit to celsius")
print(" 3: Exit")
choice=int(input("Enter choice(1/2/3): "))
if choice == 1:
fah=input("Enter Temperature in celsius:")
f=float(fah)
c=(f-32)/1.8
print("Temperature in celsius=",c)
elif choice == 2:
celsius=float(input("Enter Temperature in
fahrenheit:"))
cel=float(celsius)
fah=(9.0/5.0)*cel+32
print("Temperature in Fahrenheit=",fah)
elif choice == 3:
break
OUTPUT :

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 :

Enter a number to find factorial: 5


Factorial of 5 is: 120
5.SUM OF THE SERIES

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 :

Enter a value for n : 8


The sum of given series upto 8 is 0.3678571428571429
6.SUM & PRODUCT OF A MATRIX

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:

sum of a matrix is:


[2, 5, 5]
[8, 6, 11]
[5, 7, 9]

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 :

1.To convert your string in to uppercase


2.To convert your string in to lowercase
3.To check your string is in uppercase or not
4.To check your string is in lowercase or not
5.To join two strings
6.to print a substring from a string
7.Exit
___________________________________________
enter your choice :- 1
enter your string : hello
HELLO
enter your choice :- 6
enter a string:friend
enter your starting index value:3
enter your next value of ending index value:6
end
enter your choice :- 7
Thank you…
8.CREATE AND READ A CSV FILE
import csv
fields=['Name','Branch','Year','CGPA']
rows=[['Nikhil','COE','2','9.0'],
['Sanchit','COE','2','9.1'],
['Aditya','IT','2','9.3'],
['Sagar','SE','1','9.5']]
filename="university_records.csv"
with open(“re.csv”,'w')as csvfile:
csvwriter=csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
with open(“re.csv”, “r”) as csvfile:
csvreader=csv.reader(csvfile)
for row in csvreader:
print(‘,’.join(row))
OUTPUT :

Name, Branch, Year, salary


KARTHI, CEO, 2, 90000
MATHAN, CEO, 2, 80000
MATHAVAN, TM, 2, 60000
VIJAY, ITP, 1, 500000
DINESH, ITT, 3, 250000
9.WRITE HELLO PYTHON IN EXISTING FILE

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 :

Enter any text to write in existing file : hello python!!


Reading from existing file...
hello python!!
10.CIRCLE WITH TURTLE & CHANGE BACKGROUND COLOR

import turtle as t
while(True):
t.shape("turtle")
t.speed(1)
t.bgcolor("orange")
t.circle(100)
OUTPUT :

You might also like