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)
▶ RUN

Output/ Explanation:

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)

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad