我目前正在编写一个代码,该代码确定一家酒店的楼层入住率,该酒店有 8 层楼,每层楼有 30 间客房。我已经成功创建了循环来确定每个楼层的入住率,但是,在 for 循环完成后,我应该显示所有楼层的入住率和酒店的总入住率。你们有什么建议吗?希望对我想要实现的目标的描述足够好。我附上了一张所需程序应该如何运行的图片。先感谢您!!
print("this program will calculate a hotel's occupancy rate.")
# variable initialization
roomsOccupied = 0
floorOcupancyRate = (roomsOccupied/30) * 100
totalRoomsOccupied = 0
roomsAvailable = 30
floorOccupancyList = []
# list {1, 2, 3, 4, 5, 6, 7, 8}
# range
# user Input
for floorNbr in {1, 2, 3, 4, 5, 6, 7, 8}:
print('Current floor: ', floorNbr)
roomsOccupied = int(input('Please enter the number of rooms occupied on this floor: '))
if roomsOccupied == True:
if roomsOccupied <= roomsAvailable:
floorOccupancyList.append(roomsOccupied)
floorOccupancyRate = round((roomsOccupied/30)*100, 2)
totalRoomsOccupied += roomsOccupied
totalOccupancyRate = round((totalRoomsOccupied/240)*100, 2)
print('For floor ', str(floorNbr), 'there are a total of ', str(roomsOccupied), 'for a floor occupancy rate of ', str(floorOccupancyRate), '%')
else:
print('Invalid occupancy amouont. Please try again.')
else:
roomsOccupied =int(input('Please enter a valid room occupacy amount: '))
print('There are a total of ', totalRoomsOccupied, 'rooms occupied for a total hotel occupancy rate of ', totalOccupancyRate, '%')
print(floorOccupancyList)
# Processing
# output
print('The total number of rooms occupied is: ', totalRoomsOccupied)