0% found this document useful (0 votes)
3 views5 pages

Programming

The document contains a Python program for calculating the perimeter and area of various geometric shapes including circles, triangles, rectangles, and squares. It features a menu-driven approach allowing users to select a shape and perform calculations interactively. The program includes functions for each shape's perimeter and area, but contains several syntax errors and formatting issues that need correction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Programming

The document contains a Python program for calculating the perimeter and area of various geometric shapes including circles, triangles, rectangles, and squares. It features a menu-driven approach allowing users to select a shape and perform calculations interactively. The program includes functions for each shape's perimeter and area, but contains several syntax errors and formatting issues that need correction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#Declaring all the required functions with the

calculations of perimeter of different shapes


def per circle (radius):
perimeter = 2 *3.14 * radius
print("Perimeter of Circle:", perimeter)
def per_triangle(sidel, side2, side3):
perimeter = side1 + side2 + side3
print("Perimeter of Triangle: ", perimeter)
def per_rectangle(height, width):
perimeter = 2 * (height + width)
print("Perimeter of Rectangle:", perimeter)
def per_square(side):
perimeter = 4 * side
print("Perimeter of Square:", perimeter)
#Declaring all the required functions with the
calculations of area of different shapes
def a_circle(radius):
area =3.14 * radius * radius
print("Area of Circle: ", area)

def a_triangle(base, height):


area = base * height / 2
print("Area of Triangle:", area)
def a_rectangle(height, width):
area = height * width
print("Area of Rectangle: ",area)
def a square(side):
area = side * side
print("Area of Square:", area)

#Heading of menu-driven approach


print("\nWELCOME TO MENSURATION PROGRAM!
TRY CALCULATING PERIMETER AND AREA OF
DIFFERENT GEOMETRIC SHAPES.")

#using the while loop to print menu list


while True:
print("\nMENU")
print("1. Circle")
print("2. Triangle")
print("3. Rectangle")
print("4. Square")
print("5. Exit")
shape choice = int(input("\nEnter your choice of
shape for calculations: "))

if shape_choice == 1:
while True:
print("\n1. Calculate perimeter of Circle")
print("2. Calculate area of Circle")
print("3. Exit")
choice1 = int(input("MnEnter choice for
calculations: "))
#Calling the relevant method based on users
choice using if-else loop
if choice1 == 1:
radius = int(input("Enter Radius of Circle:
")
per_circle(radius)
elif choice1 == 2:
radius = int(input("Enter Radius of Circle:
")
a_circle(radius)
elif choice1 == 3:
break
else:
print("Incorrect Choice!")
elif shape choice == 2:
while True:
print("\n1.Calculate perimeter of Triangle")
print("2. Calculate area of Triangle")
print("3. Exit")
choice1 = int(input("nEnter choice for
calculations: ")
if choicel == 1:
sidel= int(input("Enter length of sidet: ")
side2 = int(input("Enter length of side2: "))
side3 = int(input("Enter length of side3: "))
per_triangle(side1, side2,side3)
elif choice1 == 2:
base = int(input("Enter base of traingle: "))
height = int(input("Enter height of traingle:
")
a_triangle(base, height)
elif choice1 == 3:
break
else:
print("Incorrect Choice!")

elif shape choice ==3:


while True:
print("\n1. Calculate perimeter of Rectangle")
print("2. Calculate area of Rectangle")
print("3. Exit")
choicel = int(input("nEnter choice for
calculations: "))
if choice1 ==1:
height = int(input("Enter height of
rectangle: "))
width = int(input("Enter width of rectangle:
")
per_rectangle(height, width)
elif choice1 == 2:
height = int(input("Enter height of
rectangle: "))
width = int(input("Enter width of rectangle:
")
a_rectangle(height,width)
elif choice1 == 3:
break
else:
print("Incorrect Choice!")
elif shape choice == 4:
while True:
print("n1. Calculate perimeter of Square")
print("2. Calculate area of Square")
print("3. Exit")
choice1 = int(input("nEnter choice for
calculations: "))
if choicel == 1:
side = int (input("Enter side of square: "))
per _square(side)
elif choicel == 2:
side = int (input("Enter side of square: "))
a_square(side)
elif choice1 == 3:
break
else:
print("Incorrect Choice!")
#exit condition to get out of the while loop
elif shape _choice ==5:
print("Thank You! See you again.")
break

else:
print("Incorrect Choice. Please, try again.")

You might also like