Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- Menu()
- #Prints Menu
- def Menu():
- print ("Calculate the volume of: ")
- print ("\t", "1)Box\n"
- "\t", "2)Cylinder\n"
- "\t", "3)Pyramid\n"
- "\t", "4)Sphere\n"
- "\t", "5)Exit\n")
- choice = int(input("Enter Choice : "))
- if choice == 1:
- print ("You choose to calculate the volume of a Box.")
- boxlength = float(input("Enter Length of the box: " ))
- boxwidth = float(input("Enter Width of the Box : "))
- boxheight = float(input("Enter Height of the Box : "))
- FindBoxVolume(boxlength, boxwidth, boxheight)
- elif choice == 2:
- print ("You choose to calculate the volume of a Cylinder.")
- cylinderradius = float(input("Enter Radius of the Cylinder: "))
- cylinderheight = float(input("Enter Height of the Cylinder: "))
- FindCylinderVolume(cylinderradius, cylinderheight)
- elif choice == 3:
- print("You choose to calculate the volume of a Pyramid.")
- pybase = float(input("Enter the Base of the Pyramid : "))
- pyheight = float(input("Enter the Height of the Pyramid : "))
- FindPyramidVolume(pybase, pyheight)
- elif choice == 4:
- print ("You choose to caluclate the volume of a Sphere.")
- sphereradius = float(input("Enter the Radius of the Sphere : "))
- FindSphereVolume(sphereradius)
- elif choice == 5:
- print("Press any key to exit.")
- while choice > 5:
- print ("Not Valid Choice")
- Menu()
- Menu()
- #Volume calculation methods
- import math
- from fraction import fraction
- def FindBoxVolume(length, width, height):
- print ("Calculating the Volume of a Box\n"
- "With a Length of", length, "With a Width of", width, "With a Height of", height,"\n"
- "The Volume of the Box is", (length * width * height))
- def FindCylinderVolume(radius, height):
- print("Calculating the Volume of a Cylinder\n"
- "With a Radius of",radius, "With a Height", height,"\n"
- "The Volume of the Cylinder is", (math.pi*(radius ** 2) * height))
- def FindPyramidVolume(base, height):
- print("Calculating the Volume of a Pyramid\n"
- "With a Base of", base, "With the Height of", height,"\n"
- "The Volume of the Pyramid is", (Fraction(1, 3)* (base ** 2) * height))
- def FindSphereVolume(radius):
- print("Calculating the Volume of a Sphere\n"
- "With a Radius", radius,"\n"
- "The volume of the Sphere is", (Fraction(4, 3) * math.pi * radius**3))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement