The Skyscraper Smart Lift Algorithm

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!
unlock-access

Solution...

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

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!