Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

space elevator! the international space station has built a space eleva…

Question

space elevator!
the international space station has built a space elevator with over 10,000 floors! this elevator can take tourists from houston, texas to outer space in less than a minute!
your job is to write the code for the elevator!
your task:
create a function elevator() which takes two numbers as arguments: a start floor number and an end floor number. use the range() function!
you will do this problem in two stages. first, you will create the code that makes the elevator go up!
if your passenger is riding the elevator up, your function should:

  • first print \going up!\
  • then print the number of each floor it visits as \floor n...\ where n is the number of the floor
  • then finally print \you have arrived!\ after the desired end floor is reached

here is an example of what the output should look like when the function elevator(1, 5) is called:
going up!
floor 1...
floor 2...
floor 3...
floor 4...
floor 5...
you have arrived!

starter code

def elevator(start, end):
#your code here!
print(\going up!\)

do not change the code below

elevator(1, 10)

Explanation:

Step1: Define the function

We need to create a function elevator that takes two parameters start and end. So we start with the function definition: def elevator(start, end):

Step2: Print "Going up!"

This is already partially done, but we need to make sure it's in the function. The problem says to first print "Going up!".

Step3: Loop through the floors

We use the range function to iterate from the start floor to the end floor (inclusive). In Python, range(start, end + 1) will give us the numbers from start to end (since range is exclusive of the upper bound by default). For each floor n in this range, we print f"Floor {n}..." (using an f-string for formatting).

Step4: Print "You have arrived!"

After the loop (when we've reached the end floor), we print this message.

Putting it all together, the code inside the function would be:

def elevator(start, end):
    print("Going up!")
    for n in range(start, end + 1):
        print(f"Floor {n}...")
    print("You have arrived!")

When we call elevator(1, 10) (as in the code below the function), it will print:
Going up!
Floor 1...
Floor 2...
...
Floor 10...
You have arrived!

Answer:

The code for the elevator function is as follows:

def elevator(start, end):
    print("Going up!")
    for n in range(start, end + 1):
        print(f"Floor {n}...")
    print("You have arrived!")