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
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)
Out[6]:
In [ ]: