DEV Community

Cover image for The Area or Volume of Sphere
Scott Gordon
Scott Gordon

Posted on

The Area or Volume of Sphere

# area_volume_sphere.py
#   This module has two functions in it. The first function calculates the area of a
#   sphere. The second function calculates the volume of a sphere.
# by: Scott Gordon

import math

# Create a function to calculate the area of a sphere.


def sphere_area(radius):
    area = 4 * math.pi * radius**2
    return area


# Create a function to calculate the volume of a sphere.
def sphere_volume(radius):
    volume = (4/3) * math.pi * radius**3
    return volume


# Run both functions to demonstrate their output.
def main():
    print(f"The area of the sphere is {sphere_area(2)}")
    print(f"The volume of the sphere is {sphere_volume(3)}")


main()
Enter fullscreen mode Exit fullscreen mode

Photo by Fakurian Design on Unsplash

Top comments (0)