Answer:
In Python:
floor = int(input("Number of floors: "))
totalrooms = 0
totaloccupied = 0
for i in range(floor):
rooms = int(input("Rooms in floor "+str(i+1)+": "))
occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))
totalrooms = totalrooms + rooms
totaloccupied = totaloccupied + occupied
print("Total Rooms: "+str(totalrooms))
print("Total Occupied: "+str(totaloccupied))
print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")
Step-by-step explanation:
This line prompts the user for number of rooms
floor = int(input("Number of floors: "))
This line initializes totalrooms to 0
totalrooms = 0
This line initializes totaloccupied to 0
totaloccupied = 0
This iterates through the floors
for i in range(floor):
This gets the number of rooms in each floor
rooms = int(input("Rooms in floor "+str(i+1)+": "))
This gets the number of occupied rooms in each floor
occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))
This calculates the total number of rooms
totalrooms = totalrooms + rooms
This calculates the total number of occupied rooms
totaloccupied = totaloccupied + occupied
This prints the total number of rooms
print("Total Rooms: "+str(totalrooms))
This prints the total number of occupied rooms
print("Total Occupied: "+str(totaloccupied))
This prints the percentage of occupied rooms to 2 decimal places
print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")