Advertisement
Retroledeom

Lab Activity 1

May 5th, 2022
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import math
  2.  
  3. # Volume of cube given edge length
  4. # input
  5. print("Input the edge length: ")
  6. a = float(input("a = "))
  7. # Computation of the volume, V = a^3
  8. # Since no pi is needed, math module is not needed
  9. V = a ** 3
  10. # Output of the answer
  11. print("Output:")
  12. print(f"The volume of the cube is {round(V, 3)} cu. units.")
  13.  
  14.  
  15. # Volume of Cylinder given a radius and height
  16. # input
  17. print("Input the height:")
  18. h = float(input("h = "))
  19. print("Input the radius:")
  20. r = float(input("r = "))
  21. # Computation of the Volume, V = pi * r^2 * h
  22. V = math.pi * (r ** 2) * h
  23. print("Output:")
  24. print(f"The volume of the cylinder is {round(V, 3)} cu. units.")
  25.  
  26. # Volume of Cone given a radius and height
  27. # input
  28. print("Input the height:")
  29. h = float(input("h = "))
  30. print("Input the radius:")
  31. r = float(input("r = "))
  32. # Computation of the Volume, V = 1/3 * pi * r^2 * h
  33. V = 1/3 * (math.pi * (r ** 2) * h)
  34. print("Output:")
  35. print(f"The volume of the cone is {round(V, 3)} cu. units.")
  36.  
  37. # Volume of Sphere given a radius
  38. # input
  39. print("Input radius:")
  40. r = float(input("r = "))
  41. # Computation of the Volume, 4/3 * pi * r^3
  42. V = 4/3 * (math.pi * r ** 3)
  43. print("Output:")
  44. print(f"The volume of the sphere is {round(V, 3)} cu. units.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement