EX NO: 01 Temperature Conversion 2510545
print("temperature conversion")
print("1-fahrenheit to celsius")
print("2-celsius to fahrenheit")
choice=int(input("enter your choice"))
if(choice==1):
fahrenheit=float(input("enter temperature in fahrenheit:"))
celsius=5/9*(fahrenheit-32)
print("fahrenheit:",fahrenheit,"celsius:",celsius)
else:
celsius=float(input("enter temperature in celsius"))
fahrenheit=9/5*(celsius+32)
print("celsius:",celsius,"fahrenheit:",fahrenheit)
Output:
temperature conversion
1-fahrenheit to celsius
2-celsius to fahrenheit
enter your choice1
enter temperature in fahrenheit:100
fahrenheit: 100.0 celsius: 37.77777777777778
temperature conversion
1-fahrenheit to celsius
2-celsius to fahrenheit
enter your choice2
enter temperature in celsius29
celsius: 29.0 fahrenheit: 109.8
EX NO: 2 Construct a pattern using Nested loop 2510545
n=int(input("enter number of rows."))
for i in range(n):
for j in range(n-i-1):
print(" ",end=" ")
for j in range(2*i+1):
print("*",end=" ")
print()
for i in range(n-1):
for j in range(i+1):
print(" ",end=" ")
for j in range(2*(n-i-1)-1):
print("*",end=" ")
print()
Output:
enter number of rows.5
***
*****
*******
*********
*******
*****
***
*
EX NO: 3 Calculate Student Grade 2510545
print("\t\t\t calculate the total mark,percentage and grade")
subject1=float(input("enter the subject 1marks:"))
subject2=float(input("enter the subject 2marks:"))
subject3=float(input("enter the subject 3marks:"))
subject4=float(input("enter the subject 4marks:"))
subject5=float(input("enter the subject 5marks:"))
Total=subject1+subject2+subject3+subject4+subject5
percentage=Total/5
if(percentage>=80):
print("A grade")
elif(percentage>=70 and percentage<80):
print("B grade")
elif(percentage>=60 and perentage<70):
print("C grade")
elif(percentage>=40 and percentage<60):
print("D grade")
elif(percentage<40):
print("E grade")
else:
print("Fail")
print("The total marks is:",Total)
print("The mark percentage is:",percentage,"%")
Output:
enter the subject 1marks:100
enter the subject 2marks:95
enter the subject 3marks:85
enter the subject 4marks:80
enter the subject 5marks:95
A grade
The total marks is: 455.0
The mark percentage is: 91.0 %
EX NO:4 Area of various shapes 2510545
def square_area(side):
return side*side
def rectangle_area(length,breadth):
return length*breadth
def triangle_area(base,height):
return 0.5*base*height
def circle_area(radius):
return 3.14*radius**2
print("area of various shapes")
cont='y'
while cont=='y':
print("1square\n2.rectangle\n3.triangle\n4.circle")
cho=int(input("enter your choice[1-4]:"))
if cho==1:
side=int(input("enter side of square:"))
area=square_area(side)
elif cho==2:
length=int(input("enter the length of rectangle:"))
breadth=int(input("enter the breadth of rectangle:"))
area=rectangle_area(length,breadth)
elif cho==3:
height=int(input("enter the height of triangle:"))
base=int(input("enter the base of triangle:"))
area=triangle_area(base,height)
elif cho==4:
radius=int(input("enter the radius of circle:"))
area=circle_area(radius)
print("The calculated area is:",area)
cont=input("do you want to continue?[y/n]:")
print("program exiting......")
Output:
area of various shapes
1square
2.rectangle
3.triangle
4.circle
enter your choice[1-4]:1
enter side of square:5
The calculated area is: 25
do you want to continue?[y/n]:y
program exiting......
1square
2.rectangle
3.triangle
4.circle
enter your choice[1-4]:2
enter the length of rectangle:5
enter the breadth of rectangle:10
The calculated area is: 50
do you want to continue?[y/n]:y
program exiting......
1square
2.rectangle
3.triangle
4.circle
enter your choice[1-4]:3
enter the height of triangle:10
enter the base of triangle:6
The calculated area is: 30.0
do you want to continue?[y/n]:y
program exiting......
1square
2.rectangle
3.triangle
4.circle
enter your choice[1-4]:4
enter the radius of circle:10
The calculated area is: 314.0
do you want to continue?[y/n]: