Advertisement
Guest User

Meta AI | Python code

a guest
Apr 26th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. # Ask for room dimensions (x and y)
  2. while True:
  3. try:
  4. x = float(input("Enter the length of the room in meters: "))
  5. y = float(input("Enter the width of the room in meters: "))
  6. if x > 0 and y > 0:
  7. break
  8. else:
  9. print("Please enter positive values for room dimensions.")
  10. except ValueError:
  11. print("Invalid input. Please enter a number.")
  12.  
  13. # Calculate the surface area
  14. surface_area = x * y
  15. print(f"The surface area of the room is {surface_area} square meters.")
  16.  
  17. # Ask if user wants to add room height (z)
  18. while True:
  19. add_height = input("Do you want to add a room height? (yes/no): ")
  20. if add_height.lower() in ["yes", "no"]:
  21. break
  22. else:
  23. print("Invalid input. Please enter 'yes' or 'no'.")
  24.  
  25. if add_height.lower() == "yes":
  26. # Ask for room height (z)
  27. while True:
  28. try:
  29. z = float(input("Enter the height of the room in meters: "))
  30. if z > 0:
  31. break
  32. else:
  33. print("Please enter a positive value for room height.")
  34. except ValueError:
  35. print("Invalid input. Please enter a number.")
  36.  
  37. # Calculate the volume
  38. volume = x * y * z
  39. print(f"The volume of the room is {volume} cubic meters.")
  40.  
  41. # Ask if user wants to know how many cubes fit in
  42. while True:
  43. add_cubes = input("Do you want to know how many 2x2 cubes fit in? (yes/no): ")
  44. if add_cubes.lower() in ["yes", "no"]:
  45. break
  46. else:
  47. print("Invalid input. Please enter 'yes' or 'no'.")
  48.  
  49. if add_cubes.lower() == "yes":
  50. # Calculate the number of cubes that fit in
  51. num_cubes = volume / (2 ** 3)
  52. print(f"You can fit {int(num_cubes)} cubes of 2x2 meters in the room.")
  53. else:
  54. print("No height added.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement