Python-Compute Area and Volume of A Sphere Using Functions


Write a program with a function to compute the area of a sphere and another function to compute the volume of a sphere.

#Area and volume of a sphere

#Function to compute the area of a sphere
def Area(r):
        a = 4 * 3.142 * r * r
        return a    #returns area 
# End of function

#Function to compute the volume of a sphere
def Volume(r):
        v = 4/3 * 3.142 * r * r * r
        return v    #returns volume
# End of function

#Take input
rad = int(input("Please enter the radius of the sphere "))

#Store area in variable ar
ar = Area(rad)

#Now use the value in ar to print area
print("Area = ", ar)

#Call the function Volume from print function
print ("Volume = ", Volume(rad))

#EndOfProgram
Advertisements
%d bloggers like this: