Advertisement
Guest User

Gemini | Python code

a guest
Apr 26th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. def calculate_room_metrics():
  2. while True:
  3. try:
  4. x = float(input("Enter the width of the room in meters (x): "))
  5. if x <= 0:
  6. raise ValueError("Width must be a positive number")
  7. break
  8. except ValueError as e:
  9. print("Invalid input:", e)
  10.  
  11. while True:
  12. try:
  13. y = float(input("Enter the length of the room in meters (y): "))
  14. if y <= 0:
  15. raise ValueError("Length must be a positive number")
  16. break
  17. except ValueError as e:
  18. print("Invalid input:", e)
  19.  
  20. surface_area = x * y
  21. print("The surface area of the room is:", surface_area, "square meters")
  22.  
  23. add_height = input("Do you want to add room height to calculate volume? (yes/no): ")
  24.  
  25. if add_height.lower() == 'yes':
  26. while True:
  27. try:
  28. z = float(input("Enter the height of the room in meters (z): "))
  29. if z <= 0:
  30. raise ValueError("Height must be a positive number")
  31. break
  32. except ValueError as e:
  33. print("Invalid input:", e)
  34.  
  35. volume = x * y * z
  36. print("The volume of the room is:", volume, "cubic meters")
  37.  
  38. num_cubes = int(volume / (2 * 2 * 2))
  39. print("You can fit approximately", num_cubes, "cubes (2m x 2m x 2m) in the room.")
  40. else:
  41. print("Skipping volume calculation.")
  42.  
  43.  
  44. if __name__ == "__main__":
  45. calculate_room_metrics()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement