Programming Examples

Python program to display menu to calculate area of square or rectangle


Program to display menu to calculate are of square or rectangle 

Solution

print("1. Calculate area of square")
print("2. Calculate area of rectangle ")
choice= int(input(" Enter your choice (1 or 2):"))
if(choice==1):
             side=float(input("Enter side of a square :"))
             area_square=side*side
             print("Area of square is:",area_square)
else:
                length=float(input(" Enter length of a rectangle:"))
                breadth=float(input("Enter breadth of a rectangle:"))
                area_rectangle=length*breadth
                print("Area of a rectangle is :", area_rectangle)
Output

Output  1:

1. Calculate area of square

2. Calculate area of rectangle 

 Enter your choice (1 or 2):1

Enter side of a square :2.5

('Area of square is:', 6.25)



Output 2:
1. Calculate area of square

2. Calculate area of rectangle 

 Enter your choice (1 or 2):2

 Enter length of a rectangle:8

Enter breadth of a rectangle:4

('Area of a rectangle is :', 32.0)

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad