Create a function to calculate the volume of a sphere Ensure you check for r < 0 and handle the case Use from math import pi Save this file into the folder algorithms/class2/donow with __2_donow.ipynb Commit and push to your repo Submit a PR for the Do Now


In [1]:
from math import pi

In [4]:
def calc_volume(r):
    if r < 0:
        return False
    return (4/3) * pi * (r ** 3)

In [6]:
r = float(input("Please enter the radius: "))
calc_volume(r)


Please enter the radius: 3
Out[6]:
113.09733552923254

In [ ]: