Python - Volume of a Cylinder

by matt392 in Circuits > Software

51 Views, 1 Favorites, 0 Comments

Python - Volume of a Cylinder

volumecylinder.png
print ("This program will calculate the volume of a cylinder.")

import math

#  Formula for the volume of cylinder:
#  Volume of cylinder = [(math.pi) * (radius**2) * height]

###########################################

#  1 function: solve for volume

#  Function to solve for volume
#    Solve for volume: enter radius and height 
#    Volume of cylinder = [(math.pi) * (radius**2) * height]
def SolveForVolumeCylinder():
    print ("Solving for volume of a cylinder")
#  The pi variable is coming from Python's constant: math.pi
    pi = math.pi
    Radius = float(input("Enter the radius of the cylinder: ") )
    Height = float(input("Enter the height of the cylinder: ") )
    VolumeCylinder = ( (pi) * (Radius**2) * Height)
    print("The volume of the cylinder is:", VolumeCylinder)


ContinueCalculations = "y"

# Check to see if the user wants to continue to calculate volume of cylinder
while (ContinueCalculations=="y"):
    SolveForVolumeCylinder()
    ContinueCalculations = input("Would like to do another calculation for the volume of a cylinder (y/n): ")
    
print("==================================")
print ("Thank you to www.FxSolver.com for information on this formula.")

Downloads