Untitled

 avatar
unknown
plain_text
a month ago
596 B
3
Indexable
def calculate_area(shape, values):
    if shape == "rectangle":
        return values[0] * values[1]
    elif shape == "circle":
        return 3.14159 * (values[0] ** 2)
    elif shape == "triangle":
        return 0.5 * values[0] * values[1]
    else:
        return None

shapes = ["rectangle", "circle", "triangle", "hexagon"]
values_list = [(10, 5), (7,), (6, 8), (4, 2)]

for i in range(len(shapes)):
    area = calculate_area(shapes[i], values_list[i])
    if area is not None:
        print(f"The area of the {shapes[i]} is {area}")
    else:
        print(f"Invalid shape: {shapes[i]}")
Editor is loading...
Leave a Comment