Advertisement
Guest User

Untitled

a guest
May 5th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. def main():
  2. Menu()
  3.  
  4.  
  5. #Prints Menu
  6. def Menu():
  7. print ("Calculate the volume of: ")
  8. print ("\t", "1)Box\n"
  9. "\t", "2)Cylinder\n"
  10. "\t", "3)Pyramid\n"
  11. "\t", "4)Sphere\n"
  12. "\t", "5)Exit\n")
  13. choice = int(input("Enter Choice : "))
  14.  
  15. if choice == 1:
  16. print ("You choose to calculate the volume of a Box.")
  17. boxlength = float(input("Enter Length of the box: " ))
  18. boxwidth = float(input("Enter Width of the Box : "))
  19. boxheight = float(input("Enter Height of the Box : "))
  20. FindBoxVolume(boxlength, boxwidth, boxheight)
  21. elif choice == 2:
  22. print ("You choose to calculate the volume of a Cylinder.")
  23. cylinderradius = float(input("Enter Radius of the Cylinder: "))
  24. cylinderheight = float(input("Enter Height of the Cylinder: "))
  25. FindCylinderVolume(cylinderradius, cylinderheight)
  26. elif choice == 3:
  27. print("You choose to calculate the volume of a Pyramid.")
  28. pybase = float(input("Enter the Base of the Pyramid : "))
  29. pyheight = float(input("Enter the Height of the Pyramid : "))
  30. FindPyramidVolume(pybase, pyheight)
  31. elif choice == 4:
  32. print ("You choose to caluclate the volume of a Sphere.")
  33. sphereradius = float(input("Enter the Radius of the Sphere : "))
  34. FindSphereVolume(sphereradius)
  35. elif choice == 5:
  36. print("Press any key to exit.")
  37. while choice > 5:
  38. print ("Not Valid Choice")
  39. Menu()
  40. Menu()
  41.  
  42.  
  43. #Volume calculation methods
  44. import math
  45. from fraction import fraction
  46.  
  47. def FindBoxVolume(length, width, height):
  48. print ("Calculating the Volume of a Box\n"
  49. "With a Length of", length, "With a Width of", width, "With a Height of", height,"\n"
  50. "The Volume of the Box is", (length * width * height))
  51.  
  52. def FindCylinderVolume(radius, height):
  53. print("Calculating the Volume of a Cylinder\n"
  54. "With a Radius of",radius, "With a Height", height,"\n"
  55. "The Volume of the Cylinder is", (math.pi*(radius ** 2) * height))
  56.  
  57. def FindPyramidVolume(base, height):
  58. print("Calculating the Volume of a Pyramid\n"
  59. "With a Base of", base, "With the Height of", height,"\n"
  60. "The Volume of the Pyramid is", (Fraction(1, 3)* (base ** 2) * height))
  61.  
  62. def FindSphereVolume(radius):
  63. print("Calculating the Volume of a Sphere\n"
  64. "With a Radius", radius,"\n"
  65. "The volume of the Sphere is", (Fraction(4, 3) * math.pi * radius**3))
  66.  
  67.  
  68. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement