To calculate perimeter/ circumference and area of shapes such as triangle, rectangle, square and circle
Here we are going to write menu driven program To calculate perimeter/ circumference and area of shapes such as triangle, rectangle, square and circle
Program:
import math
# creating options
while True:
print("\nMAIN MENU")
print("1. Calculate Area and Parameter of square")
print("2. Calculate Area and Perimeter of circle")
print("3. Calculate Area and Perimeter of rectangle")
print("4. Calculate Area and Perimeter of triangle")
print("5. Exit")
choice = int(input("Enter the Choice:"))
if choice == 1:
s=float(input("Enter the side of square:"))
# Calculating area of square (aos)
print("\nCALCULATE AREA OF SQUARE")
aos=float(s*s);
print("Area of square is:",aos)
print("\nCALCULATE PARAMETER OF SQUARE")
# Calculating perimeter of square (pos)
pos=float(4*s);
print("Perimeter of square is:",pos)
break
if choice ==2:
r=float(input("Enter the radius of circle:"))
# Calculating area of circle (aoc)
aoc=float(3.14*r*r);
print("Area of circle is:",aoc)
# Calculating perimeter of square (pos)
poc=float(2*3.14*r);
print("Perimter of circle is:",poc)
break
if choice ==3:
l=float(input("Enter the length of rectangle:"))
b=float(input("Enter the breadth of rectangle:"))
# Calculating area of rectangle (aor)
aor=float(l*b);
print("Area of rectangle is:",aor)
# Calculating perimeter of rectangle (por)
por=float(2*(l+b))
print("Perimter of rectangle is:",por)
break
if choice ==4:
bs=float(input("Enter the base of right angled triangle:"))
h=float(input("Enter the height of right angled triangle:"))
# Calculating area of triangle (aot)
aot=float((bs*h)/2);
print("Area of triangle is:",aot)
hypotenuse=float(math.sqrt(bs*bs+h*h))
# Calculating perimeter of right angle triangle (pot)
pot=float(bs+h+hypotenuse)
print("Perimter of right angled triangle is:",pot)
break
else:
print("Oops! Please enter correct Choice.")
Output:
>>> %Run 11ip2menu.py MAIN MENU 1. Calculate Area and Parameter of square 2. Calculate Area and Perimeter of circle 3. Calculate Area and Perimeter of rectangle 4. Calculate Area and Perimeter of triangle 5. Exit Enter the Choice:1 Enter the side of square:5 CALCULATE AREA OF SQUARE Area of square is: 25.0 CALCULATE PARAMETER OF SQUARE Perimeter of square is: 20.0 >>> %Run 11ip2menu.py MAIN MENU 1. Calculate Area and Parameter of square 2. Calculate Area and Perimeter of circle 3. Calculate Area and Perimeter of rectangle 4. Calculate Area and Perimeter of triangle 5. Exit Enter the Choice:3 Enter the length of rectangle:4 Enter the breadth of rectangle:5 Area of rectangle is: 20.0 Perimter of rectangle is: 18.0
<