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

python program examples it computer guruji

Write a program in python to display menu to calculate area of square or rectangle

------------------------------
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 the side of a square : "))
       area_square=side*side
       print("Area of square is : ",area_square)
else:
       l=float(input(" Enter the length of a rectangle : "))
       b=float(input("Enter the breadth of a rectangle : "))
       area_rectangle=l*b
       print("Area of a rectangle is : ", area_rectangle)
------------------------------

Output-1

1. Calculate Area of square

2. Calculate Area of rectangle 

Enter your choice (1 or 2) : 1

Enter the side of a square : 3.5

Area of square is :  12.25

Output-2

1. Calculate Area of square

2. Calculate Area of rectangle 

Enter your choice (1 or 2) : 2

Enter the length of a rectangle : 5

Enter the breadth of a rectangle : 4

Area of a rectangle is : 20.0


Post a Comment

0 Comments