Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
5
Indexable
Never
import math

def calculate_area(sides, angles, distances):
    # Check if the number of sides matches the number of angles and distances
    if len(angles) != sides or len(distances) != sides:
        print("Invalid input: Number of angles/distances doesn't match the number of sides.")
        return None

    # Convert angles to radians
    angles_rad = [math.radians(angle) for angle in angles]

    # Initialize area
    area = 0

    # Calculate area using coordinates method
    for i in range(sides):
        j = (i + 1) % sides
        area += distances[i] * distances[j] * math.sin(angles_rad[i] + angles_rad[j])

    area /= 2

    return abs(area)

def main():
    # Input number of sides
    sides = int(input("Enter the number of sides of the polygon (3 to 7): "))
    if sides < 3 or sides > 7:
        print("Invalid number of sides. Exiting...")
        return

    # Input angles
    angles = []
    for i in range(sides):
        angle = float(input(f"Enter the angle {i+1} in degrees: "))
        angles.append(angle)

    # Input distances
    distances = []
    for i in range(sides):
        distance = float(input(f"Enter the distance {i+1}: "))
        distances.append(distance)

    # Calculate area
    area = calculate_area(sides, angles, distances)
    if area is not None:
        print(f"The area of the traverse is: {area} square units.")

if __name__ == "__main__":
    main()
Leave a Comment