Imagine you are the lead developer for a cutting-edge, luxurious hotel housed in a 101-floor skyscraper. The hotel’s main lift needs a smart algorithm to efficiently transport guests to their rooms. Each floor has seven rooms, and the numbering starts from the ground floor (Floor 0) with rooms 1 to 7, then Floor 1 with rooms 8 to 14, and so on, up to Floor 100 with rooms 701 to 707.
The smart lift of this hotel is equipped with a keypad that let the guests enter their room number.
Your challenge is to write a Python algorithm to control this smart lift. Your algorithm will need to:
-
Take a room number as input
Validate this room number to only accept room numbers between 1 and 707 and display an error message if the room number is invalid
Calculate and output the corresponding floor number that the lift will have to reach.
Key Insight
You may decide to solve this problem by yourself. Alternatively you can read through the following guidance to help you solve this challenge.
Let’s first make sense of the room numbering pattern:
- Ground Floor (Floor 0): Rooms 1, 2, 3, 4, 5, 6, 7
- Floor 1: Rooms 8, 9, 10, 11, 12, 13, 14
- Floor 2: Rooms 15, 16, 17, 18, 19, 20, 21
- …
- Floor 100: Rooms 701, 702, 703, 704, 705, 706, 707
The floor number for any given room can be calculated using integer division (//). For example:
Room 24: 24 // 7 = 3. This room will be located on the 3rd floor.
However we need to be cautious, as just applying an integer division will not work for every room:
For instance: Room 7: 7 // 7 = 1 though we know that room 7 should be on the ground floor (0).
We can therefore define a formula to help us get the correct floor number for every valid room number:

Python Code
Your turn, use the online Python IDE below to complete the code for this challenge. Then you will be able to test your code with the test plan provided below the Python IDE.
Test Plan
Use the following test plan to test your code:
| Input | Expected Output | Pass/Fail? |
|---|---|---|
| Room Number: 5 | Ground Floor | |
| Room Number: 12 | 1 | |
| Room Number: 16 | 2 | |
| Room Number: 21 | 2 | |
| Room Number: 22 | 3 | |
| Room Number: 76 | 10 | |
| Room Number: 101 | 14 | |
| Room Number: 707 | 100 | |
| Room Number: 708 | Invalid Room Number! |
Extension Task: The 13th Floor!
In America, many high-rise buildings, hotels, and hospitals omit the 13th floor from their elevator panels and floor numbering. This is due to the fact that 13 is considered as an unlucky number. So instead, superstitious builders often skip from floor 12 to 14.
This would mean that the program for our lift would need to be tweaked so that for any floor above 12, it will add 1 to the floor number so that floor 13 is displayed as 14, floor 14 is displayed as 15 and so on up until floor 100 that will be displayed as floor 101.
Your task is to amend the code to cater for such building where there is no 13th floor!
You can then test your code with this new test plan:
| Input | Expected Output | Pass/Fail? |
|---|---|---|
| Room Number: 5 | Ground Floor | |
| Room Number: 16 | 2 | |
| Room Number: 88 | 12 | |
| Room Number: 97 | 14 | |
| Room Number: 101 | 15 | |
| Room Number: 707 | 101 | |
| Room Number: 708 | Invalid Room Number! |

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area







