In: Computer Science
1) Write a simple python function program that can calculate the volumes of following shape: cylinder, circle, cone and sphere. For each of this shape, write a separate function. Let your function take in 2 inputs only. Your program should prompt user to enter these 2 inputs and print out the results of the volumes of the shape separately?
Circle does not have volume as it is 2 dimensional figure it only has area and circumference.
CODE-
#Function for calculating cylinder volume
def vol_cylinder(height,radius):
pi=22/7
global volume_cyl
volume_cyl = pi * radius * radius * height
#Function for calculating circle area
def area_circle(radius):
pi=22/7
global area
area = pi * radius * radius
#Function for calculating cone volume
def vol_cone(height,radius):
pi=22/7
global volume_cone
volume_cone = (pi * radius * radius * height)/3
#Function for calculating sphere volume
def vol_sphere(radius):
pi=22/7
global volume_sphere
volume_sphere = (4 * pi * radius * radius * radius)/3
#taking user input for height and radius of cylinder
height = float(input('Enter Height of cylinder: '))
radius = float(input('Enter Radius of cylinder: '))
vol_cylinder(height,radius)
#taking user input for radius of circle
print("=======================================")
radius = float(input('Enter Radius of circle: '))
area_circle(radius)
#taking user input for height and radius of cone
print("=======================================")
height = float(input('Enter Height of cone: '))
radius = float(input('Enter Radius of cone: '))
vol_cone(height,radius)
#taking user input for height and radius of sphere
print("=======================================")
radius = float(input('Enter Radius of sphere: '))
vol_sphere(radius)
#Printing all volumes separately
print("\nVolume of cylinder is: ", volume_cyl)
print("Area of circle is: ", area)
print("Volume of cone is: ", volume_cone)
print("Volume of sphere is: ", volume_sphere)
Output-