"""Find the area of various geometric shapes"""from math import pidef surface_area_cube(side_length: float) -> float:"""Calculate the Surface Area of a Cube.>>> surface_area_cube(1)6>>> surface_area_cube(3)54"""return 6 * side_length ** 2def surface_area_sphere(radius: float) -> float:"""Calculate the Surface Area of a Sphere.Wikipedia reference: https://en.wikipedia.org/wiki/Sphere:return 4 * pi * r^2>>> surface_area_sphere(5)314.1592653589793>>> surface_area_sphere(1)12.566370614359172"""return 4 * pi * radius ** 2def area_rectangle(length: float, width: float) -> float:"""Calculate the area of a rectangle>>> area_rectangle(10,20)200"""return length * widthdef area_square(side_length: float) -> float:"""Calculate the area of a square>>> area_square(10)100"""return side_length ** 2def area_triangle(base: float, height: float) -> float:"""Calculate the area of a triangle>>> area_triangle(10,10)50.0"""return (base * height) / 2def area_parallelogram(base: float, height: float) -> float:"""Calculate the area of a parallelogram>>> area_parallelogram(10,20)200"""return base * heightdef area_trapezium(base1: float, base2: float, height: float) -> float:"""Calculate the area of a trapezium>>> area_trapezium(10,20,30)450.0"""return 1 / 2 * (base1 + base2) * heightdef area_circle(radius: float) -> float:"""Calculate the area of a circle>>> area_circle(20)1256.6370614359173"""return pi * radius ** 2def main():print("Areas of various geometric shapes: \n")print(f"Rectangle: {area_rectangle(10, 20)}")print(f"Square: {area_square(10)}")print(f"Triangle: {area_triangle(10, 10)}")print(f"Parallelogram: {area_parallelogram(10, 20)}")print(f"Trapezium: {area_trapezium(10, 20, 30)}")print(f"Circle: {area_circle(20)}")print("\nSurface Areas of various geometric shapes: \n")print(f"Cube: {surface_area_cube(20)}")print(f"Sphere: {surface_area_sphere(20)}")if __name__ == "__main__":import doctestdoctest.testmod(verbose=True) # verbose so we can see methods missing testsmain()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。