In: Computer Science
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
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("Total number of
floors in the hotel : 8") print("-----------------------------------\n") total_in_floor = 30
print("Please enter rented
rooms in Floor No. {0}".format(i+1)) 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("Total number of floors in the hotel : 8") print("-----------------------------------\n") total_in_floor = 30 for i in range(8): unoccupied_in_hotel = 0 |
OUTPUT
NOTE : Uses the term rented in place of occupied