alperen dikici

Area Calculator

Calculate the area of various geometric shapes.

Select a shape:

Source Code (Python)

# coding=utf-8

"""
    Calculate areas of geometric shapes
"""


def square(side):
    print("Area of square = {}".format(side * side))


def rectangle(length, width):
    print("Area of rectangle = {}".format(length * width))


def trapezoid(base1, base2, height):
    print("Area of trapezoid = {}".format(((base1 + base2) * height) / 2))


def parallelogram(base, height):
    print("Area of parallelogram = {}".format(base * height))


def rhombus(diagonal1, diagonal2):
    print("Area of rhombus = {}".format((diagonal1 * diagonal2) / 2))


if __name__ == '__main__':
    print("""
    1 - Square
    2 - Rectangle
    3 - Trapezoid
    4 - Parallelogram
    5 - Rhombus
    """)

    choice = int(input("Shape to calculate area: "))

    if choice == 1:
        side = int(input("Side of square: "))
        square(side)

    elif choice == 2:
        length = int(input("Length of rectangle: "))
        width = int(input("Width of rectangle: "))
        rectangle(length, width)

    elif choice == 3:
        base1 = int(input("Lower base of trapezoid: "))
        base2 = int(input("Upper base of trapezoid: "))
        height = int(input("Height of trapezoid: "))
        trapezoid(base1, base2, height)

    elif choice == 4:
        base = int(input("Base of parallelogram: "))
        height = int(input("Height of parallelogram: "))
        parallelogram(base, height)

    elif choice == 5:
        diagonal1 = int(input("First diagonal of rhombus: "))
        diagonal2 = int(input("Second diagonal of rhombus: "))
        rhombus(diagonal1, diagonal2)

    else:
        print("Please enter only one of the specified numbers.")