Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculate_room_metrics():
- while True:
- try:
- x = float(input("Enter the width of the room in meters (x): "))
- if x <= 0:
- raise ValueError("Width must be a positive number")
- break
- except ValueError as e:
- print("Invalid input:", e)
- while True:
- try:
- y = float(input("Enter the length of the room in meters (y): "))
- if y <= 0:
- raise ValueError("Length must be a positive number")
- break
- except ValueError as e:
- print("Invalid input:", e)
- surface_area = x * y
- print("The surface area of the room is:", surface_area, "square meters")
- add_height = input("Do you want to add room height to calculate volume? (yes/no): ")
- if add_height.lower() == 'yes':
- while True:
- try:
- z = float(input("Enter the height of the room in meters (z): "))
- if z <= 0:
- raise ValueError("Height must be a positive number")
- break
- except ValueError as e:
- print("Invalid input:", e)
- volume = x * y * z
- print("The volume of the room is:", volume, "cubic meters")
- num_cubes = int(volume / (2 * 2 * 2))
- print("You can fit approximately", num_cubes, "cubes (2m x 2m x 2m) in the room.")
- else:
- print("Skipping volume calculation.")
- if __name__ == "__main__":
- calculate_room_metrics()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement