Countdown to launch

Countdown to launch

3...2...1...lift off.

Try


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Knowledge Organiser

Command summary

The new commands used in this program and others that may be useful. Select them below to learn more:

for

Is used to repeat an indented section of code underneath the statement a known number of times.


Note The `while` command is used when you don't know how many iterations will be required, but `for` is used when the number of iterations is known.


Although you can use a while loop instead of a for loop as shown in the example below, it is not considered good practice unless the value of counter can be changed by another command in addition to the increment statement.


counter = 0

while counter < 5:

counter = counter + 1 # This is the increment statement.

range(x, y, z)

Defines a range of numbers to be used by a for loop: x is the starting number, y is the finishing number and z is the increment/decrement applied to x to reach y in each iteration.

range(5)

Means the numbers 0 to 4. Note that it is not necessary to state the starting number or the increment if the loop starts at 0 and increases by 1 in each iteration.

time.sleep(x)

Delays the next line of code executing for x number of seconds. Requires import time to access these commands.

import time

Includes functions from a library called `time` in your program. These are date, time and delay functions.

Investigate


Questions to think about with this program to check your understanding:

Item question

Identify an iteration ending condition and a step decrement in the program.

REVEAL ANSWER

The iteration ending condition is `counter = 0`.

The step decrement is -1.

Structure question

State all the parts of a for loop statement.

REVEAL ANSWER
  1. The command `for`.
  2. Counting variable.
  3. The keyword `in`.
  4. A range to iterate over including: an optional start value for the counting variable, an iterating ending value/condition and an optional counting step.

Make


Success Criteria

Change the program so that it:

  1. Starts the countdown at 12.
  2. After 9 it outputs, "Ignition sequence start." before continuing the countdown.

Typical inputs and outputs from the program would be:

T minus...

12 ...

11 ...

10 ...

9 ...

Ignition sequence start.

8 ...

7 ...

6 ...

5 ...

4 ...

3 ...

2 ...

1 ...

0 ...

All engines running.

Lift off, we have a lift off on Artemis 1.

Tower clear.

Help

Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.

Evaluate


Run your code to check that your program has met the success criteria and produces the required output.

T minus...

12 ...

11 ...

10 ...

9 ...

Ignition sequence start.

8 ...

7 ...

6 ...

5 ...

4 ...

3 ...

2 ...

1 ...

0 ...

All engines running.

Lift off, we have a lift off on Artemis 1.

Tower clear.