Answer:
# Get the number of floors from the user
floors = int(input("How many floors does the hotel have? "))
# Initialize variables to keep track of the number of rooms and occupied rooms
total_rooms = 0
total_occupied_rooms = 0
# Loop once for each floor
for floor in range(floors):
# Get the number of rooms and occupied rooms on this floor
rooms = int(input("How many rooms are on floor " + str(floor + 1) + "? "))
occupied_rooms = int(input("How many of these rooms are occupied? "))
# Update the total number of rooms and occupied rooms
total_rooms += rooms
total_occupied_rooms += occupied_rooms
# Calculate the percentage of rooms that are occupied
occupancy_rate = (total_occupied_rooms / total_rooms) * 100
# Display the results
print("The hotel has a total of", total_rooms, "rooms.")
print("There are", total_occupied_rooms, "occupied rooms.")
print("There are", total_rooms - total_occupied_rooms, "unoccupied rooms.")
print("The occupancy rate is", occupancy_rate, "%.")
Step-by-step explanation:
This program uses a for loop to iterate once for each floor. On each iteration, it gets the number of rooms and occupied rooms on the floor from the user and updates the total number of rooms and occupied rooms accordingly. Finally, it calculates the occupancy rate and displays the results.