5.11. Project: Conditional Launch

Complete this project to boost your conditional skills. Don’t worry if you struggle a bit. Struggling (and needing to review) before succeeding is a natural and frequent part of coding. Making mistakes helps you learn.


There is no starter code for this project. However, if your teacher uses a Trinket course, you will submit your work there.

Otherwise, login to your repl.it or Trinket account and start a new project.

5.11.1. Spacecraft Data

Use the following variables for a spacecraft we want to launch:

Variable Value
engine_indicator_light "red blinking"
space_suits_on True
shuttle_cabin_ready True
crew_status space_suits_on and shuttle_cabin_ready
computer_status_code 200

5.11.2. Part A: PREDICT

  1. Examine the code below. What will be printed to the console?

    Use the value of engine_indicator_light assigned above to answer this question.

    if engine_indicator_light == "green":
       print("Engines started")
    elif engine_indicator_light == "green blinking":
       print("Engines preparing to start")
       print("Engines off")
  2. Do these two code blocks produce the same result?

    # Code block 1
    if crew_status and computer_status_code == 200 and space_suits_on:
       print("All systems go!")
       print("WARNING! Not ready.")
    # Code block 2
    if not crew_status or computer_status_code != 200 or not space_suits_on:
       print("WARNING. Not ready")
       print("All systems go!")

5.11.3. Part B: Cabin Safety Checks

  1. Use an input statement to prompt the user to enter the speed of the spacecraft. Store this result in the variable spacecraft_speed. Remember to convert the input from the str data type to int or float.
  2. Write conditional expressions to satisfy the safety rules below. Use spacecraft_speed and the same variables defined at the top of the page.
    1. crew_status
      • If the value is True, print "Crew Ready"
      • Else print "Crew Not Ready"
    2. computer_status_code
      • If the value is 200, print "Please stand by. Computer is rebooting."
      • Else, if the value is 400, print "Success! Computer online."
      • Else print "ALERT: Computer offline!"
    3. spacecraft_speed
      • If the speed is > 17500, print "ALERT: Escape velocity reached!"
      • Else, if the speed is < 8000, print "ALERT: Cannot maintain orbit!"
      • Else print "Stable speed"
  3. Before you move to part C, run your program several times to test your code. Change only ONE variable value at a time to make sure your conditionals print the expected results.
    1. Change the value of space_suits_on to False.
    2. Change computer_status_code to 400, then 100.
    3. Enter different values for spacecraft_speed. (Tip: 17500 and 8000 should both produce Stable speed).


In step 3, you are trying to make your code fail. Testing helps you spot and fix bugs!

5.11.4. Part C: Fuel Safety Checks

Define two new variables:

Variable Value
fuel_level 10000
engine_temperature 2000
  1. Use if/elif/else statements to monitor the spacecraft’s fuel status. Order is important when working with conditionals, and the checks below are NOT written in the correct sequence.

    Read ALL of the checks before coding and decide on the best order for the statements.

    1. If fuel_level is above 20000 AND engine_temperature is at or below 2500, print "Full tank. Engines good."
    2. If fuel_level is above 10000 AND engine_temperature is at or below 2500, print "Fuel level above 50%.  Engines good."
    3. If fuel_level is above 5000 AND engine_temperature is at or below 2500, print "Fuel level above 25%. Engines good."
    4. If fuel_level is at or below 5000 OR engine_temperature is above 2500, print "ALERT: Check fuel level and engine temperature."
    5. If fuel_level is below 1000 OR engine_temperature is above 3500 OR engine_indicator_light is red blinking, print "ENGINE FAILURE IMMINENT!"
    6. Otherwise, print "Fuel and engine status pending..." Test Your Fuel Status Code

Run your code several times to make sure it prints the correct phrase for each set of conditions. The table below gives you some practice values as well as the expected output.

fuel_level engine_temperature engine_indicator_light Result
21000 1200 NOT red blinking Full tank. Engines good.
5000 1200 NOT red blinking ALERT: Check fuel level and engine temperature.
12000 2600 NOT red blinking ALERT: Check fuel level and engine temperature.
10000 2500 NOT red blinking Fuel level above 25%. Engines good.

5.11.5. A Final Bit of Fun!

The spacecraft should only launch if the fuel tank is full and the engine check is OK. However, let’s establish an override command to ignore any warnings and send the ship into space anyway!

  1. Create the variable command_override, and set it to be True or False.

    If command_override is False, then the shuttle should only launch if the fuel and engine check are OK.

    If command_override is True, then the shuttle will launch regardless of the fuel and engine status.

  2. Code the following if/else check:

    If fuel_level is above 20000 AND engine_indicator_light is NOT red blinking OR command_override is True, print "Cleared to launch!"

    Else print "Launch scrubbed!"