Question

In: Computer Science

I need to make an application that calculates the occupancy rate for a hotel with eight...

I need to make an application that calculates the occupancy rate for a hotel with eight floors. The user will be asked how many rooms are occupied on each floor. The program will iterate for each floor. Users must enter numbers and the rooms occupied on each floor cannot exceed 30. The occupancy rate is the number of occupied rooms/ unnoccupied.  The application also needs to display the occupancy for each individual floor aswell. Each floor has a maximum of 30 rooms. There are 240 rooms in total. The application doesn't need any fancy graphics just simple text. I'm really lost where to start. I know I need to use for loops and while but I'm not sure how to apply it. Can I get some help?

Python

The code needs to be in Python

Solutions

Expert Solution

NOTE :For your kind information , the actual formula for occupancy rate is

Occupancy rate = (Total number or rooms occupied) / (Number of rooms occupied + Number of rooms unoccupied)

As you specified occupancy rate as rooms occupied /rooms unoccupied , I am doing calculations for both formulas and providing the code and outputs. Please copy the one you needed.

Hereby , giving the python code for the application you needed.

CODE :

FORMULAS USED :

Occupancy rate of each floor = (Occupied rooms in each floor) / (Total rooms in each floor)

Occupancy rate for hotel = (Occupied rooms in hotel)/(Total rooms in hotel)

NOTE : PLEASE READ THE COMMENTS IN THE SCREENSHOT FOR BETTER UNDERSTANDING

DON'T RUN PYTHON SCRIPT WITH COMMENTS , IT MAY MISBEHAVE . FOR THAT REASON I HAVEN"T MENTIONED COMMENTS FOR THE CODE BELOW


print("WELCOME TO THE GRAND NEW HOTEL!!!")
print("-----------------------------------")

print("Total number of floors in the hotel : 8")
print("Total number of rooms in each floor : 30")
print("Total Number of rooms in the hotel :240\n")

print("-----------------------------------\n")

total_in_floor = 30
total_in_hotel = 240
rented_in_floor = 0
rented_in_hotel = 0
rate_of_floor = 0
rate_of_hotel = 0


for i in range(8):

print("Please enter rented rooms in Floor No. {0}".format(i+1))
rented_in_floor = int(input())
if rented_in_floor>30:
print("There are only 30 rooms in each floor")
exit()
rate_of_floor = int((rented_in_floor))/int((total_in_floor))*100
print("Occupancy rate of Floor No.{0} is = {1}%\n".format(i+1,round(rate_of_floor,2)))
  
rented_in_hotel = int(rented_in_hotel) + int(rented_in_floor)

rate_of_hotel = int((rented_in_hotel))/int((total_in_hotel))*100

print("Total rooms rented in entire hotel : {0}\n".format(rented_in_hotel))

print("Occupancy rate of the hotel is = {0} % \n".format(round(rate_of_hotel,2)))

PLEASE CHECK THE INDENTATIONS , THE CODE WORKS PROPERLY . IF YOU HAVE ANY ISSUES , IT MAY BE DUE TO INDENTATIONS AND UNNECESSARY DOTS MAY BE INCLUDED WHILE YOU COPY IT FROM THE ANSWER PAGE.

Please copy the code and see it in any online compiler to see where the indentations lost and dots are added. I have copied it from editor after having proper output please check indentations and check code in a black background editor to see if any dots included .

OUTPUT

OUTPUT IF USER ENTERS MORE THAN 30 FOR ROOMS IN A FLOOR

SCREENSHOTS OF THE CODE :

Please see the screenshots for the indentation of code.

IT SEEMS THE FORMULA YOU SPECIFIED GIVES ABNORMAL RESULTS. PLEASE CHECK THE BELOW CODE ONCE.

I AM GIVING THE CODE AS YOU SPECIFIED THE FORMULA .

PLEASE USE THE ABOVE CODE FOR CORRECT RESULTS.

Code for the formula you mentioned

FORMULAS USED :

Occupancy rate of each floor = (rooms occupied in each floor)/(rooms unoccupied in each floor)

Occupancy rate of hotel = (rooms occupied in all floors) / (rooms unoccupied in all floors)


print("WELCOME TO THE GRAND NEW HOTEL!!!")
print("-----------------------------------")

print("Total number of floors in the hotel : 8")
print("Total number of rooms in each floor : 30")
print("Total Number of rooms in the hotel :240\n")

print("-----------------------------------\n")

total_in_floor = 30
total_in_hotel = 240
rented_in_floor = 0
rented_in_hotel = 0
rate_of_floor = 0
rate_of_hotel = 0
unoccupied = 0

for i in range(8):
print("Please enter rented rooms in Floor No. {0}".format(i+1))
rented_in_floor = int(input())
if rented_in_floor > 30:
print("There are only 30 rooms in each floor")
exit()   
unoccupied = int(total_in_floor)-int(rented_in_floor)
if unoccupied > 0:
  
rate_of_floor = int((rented_in_floor))/int(unoccupied)*100
else:
rate_of_floor = 100
print("Occupancy rate of Floor No.{0} is = {1}%\n".format(i+1,round(rate_of_floor,2)))
rented_in_hotel = int(rented_in_hotel) + int(rented_in_floor)

unoccupied_in_hotel = 0
unoccupied_in_hotel = int(total_in_hotel)-int(rented_in_hotel)
print(unoccupied_in_hotel)
if unoccupied_in_hotel >0:
rate_of_hotel = int(rented_in_hotel)/int(unoccupied_in_hotel)*100
else :
rate_of_hotel = 100
print("Total rooms rented in entire hotel : {0}\n".format(rented_in_hotel))
print("Occupancy rate of the hotel is = {0} % \n".format(round(rate_of_hotel,2)))

OUTPUT

NOTE : Uses the term rented in place of occupied


Related Solutions

Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...
Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor. Your program should display the following: How...
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations, the program...
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.
Use JAVAProgram #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
Operation  This application calculates the charges for a stay at a hotel based on the...
Operation  This application calculates the charges for a stay at a hotel based on the arrival and departure dates.  The application begins by prompting the user for the month, day, and year of the arrival and the departure.  Next, the application displays the arrival date, the departure date, the room rate, the total price, and the number of nights. Specifications  Create a class named Reservation that defines a reservation. This class should contain instancevariables for the...
Following are the number of victories for the Blue Sox and the hotel occupancy rate for...
Following are the number of victories for the Blue Sox and the hotel occupancy rate for the past eight years. You have been asked to test three forecasting methods to see which method provides a better forecast for the Number of Blue Sox Wins. Year Number of Blue Sox Wins Occupancy Rate 1 70 78% 2 67 83 3 75 86 4 87 85 5 87 89 6 91 92 7 89 91 8 85 94 For the following, you...
I need to make JAVA program that calculates the area of a brick of a specific...
I need to make JAVA program that calculates the area of a brick of a specific color. I have class Brick with the following UML: String color int number int length int width I made methods: getColor(), getNumber(), getLength(), getWidth() in the class Brick So it starts like this: ##### public Brick(String color, int number, int length, int width) { this.color = color; this.number = number; this.length = length; this.width = width;    }   public String toString() {   return number...
C++ application that calculates the sales at the end of the day. Need to know how...
C++ application that calculates the sales at the end of the day. Need to know how much money I made on selling my famous banana muffins each day. At the end of each day I must not only enter the number of banana muffins I sold but I must also enter the price of the banana muffins. Each day I have to experiment with changing the price in an attempt to maximize my revenues for his muffins. I also want...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT