find the volume of a sphere in python

To calculate the volume of a sphere in Python, we need to use the formula V = (4/3) * pi * r^3 where pi is a constant with a value of 3.141592653589793 and r is the radius of the sphere.

Here's the Python code to find the volume of a sphere:

main.py
import math

def find_sphere_volume(radius):
    pi = math.pi
    volume = (4/3) * pi * (radius ** 3)
    return volume

print(find_sphere_volume(5))
150 chars
9 lines

In this code, we first import the math module to use the constant pi. Then, we define a function called find_sphere_volume that takes the radius of the sphere as its parameter. Inside the function, we calculate the volume of the sphere using the formula and return the result.

We then call the function with a radius of 5 and printout the result. The output should be:

main.py
523.5987755982989
18 chars
2 lines

gistlibby LogSnag