#This program will ask for a shape and #calculate the area and perimeter import math print("Select a shape:") print("1. Square") print("2. Rectangle") print("3. Circle") print("4. Hexagon") print("5. Decagon") keep_going = "" while keep_going == "": shape = input("Choose a number from 1-5. ") if shape == "1": print("You chose square.") square_side = float(input("Enter the length of a side: ")) if square_side < 0: raise ValueError("Side length cannot be negative.") square_area = side **2 square_perimeter = side * 4 print(f"The perimeter of a square with a length of {side} is {square_perimeter}.\n" f"The area is {square_area}.") elif shape == "2": print("You chose rectangle.") length = float(input("Enter the length of a side: ")) width = float(input("Enter the length of another side: ")) if length or width < 0: raise ValueError("Side length cannot be negative.") rectangle_area = length * width rectangle_perimeter = 2 * (length + width) print(f"The perimeter of a rectangle with a length of {length} and a width of {width} is {rectangle_perimeter}.\n" f"The area is {rectangle_area}.") elif shape == "3": print("You chose circle.") radius = float(input("Enter the length of the radius: ")) if radius < 0: raise ValueError("radius length cannot be negative.") circle_area = 3.14159 * (radius ** 2) circle_circumference = 2 * 3.14159 * radius print(f"The circumference of a circle with a radius of {radius} is {circle_circumference}.\n" f"The area is {circle_area}.") elif shape == "4": print("You chose hexagon.") hexagon_side = float(input("Enter the length of the side: ")) def hexagon_area(hexagon_side): if hexagon_side < 0: raise ValueError("Side length cannot be negative.") return (3 * math.sqrt(3) / 2) * (hexagon_side ** 2) area = hexagon_area(hexagon_side) hexagon_perimeter = hexagon_side * 6 print(f"The area of a hexagon with a length of {hexagon_side} is {area:.2f}.\n" f"The perimeter is {hexagon_perimeter:.2f}.") elif shape == "5": print("You chose decagon.") decagon_side = float(input("Enter the length of the side: ")) def decagon_area(decagon_side): """Calculates the area of a regular decagon given its side length.""" if decagon_side < 0: raise ValueError("Side length cannot be negative.") constant_part = math.sqrt(5 + 2 * math.sqrt(5)) area = (5 / 2) * (decagon_side ** 2) * constant_part return area area = decagon_area(decagon_side) perimeter = 10 * decagon_side print(f"The area of a decagon with a length of {decagon_side} is {area}.\n" f"The perimeter is {perimeter:.2f}.") else: print("You entered an invalid option.") keep_going = input("Press enter to keep calculating, or type anything else to exit. ") if keep_going != "": print(f"Time to study!") print("This program has ended")