DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›