YEAR 9 DIGITAL TECHNOLOGIES • IMPORTS CHALLENGE

Airport Security Challenge

In this challenge, you will use imports to build a simple airport security system.

✈️ SCENARIO

Imagine you are writing a Python program for an airport security gate.

The airport security system must decide whether a passenger:

  • is blocked because the airport is closed
  • is sent to extra screening
  • or is allowed through

To do that, the program will use two imports: datetime and random.

🎯 YOUR GOAL

Build a program that follows these rules:

  1. Check the current hour.
  2. If the airport is closed, stop there.
  3. If the airport is open, generate a random number.
  4. If that number divides exactly by 7, send the passenger to extra screening.
  5. Otherwise, allow the passenger through.
Challenge Brief

Your airport security program should work like this:

Step 1: Check the time
The airport is only open between 6 and 22.
Step 2: If closed
Print a message saying the airport is closed.
Step 3: If open
Generate a random number.
Step 4: Screening check
If the random number divides exactly by 7, send the passenger to extra screening.

Important: Build the logic yourself first. Do not jump straight to the hint or example code.

💭 WHAT YOU SHOULD THINK ABOUT
  • What does an import do?
  • How do you get the current hour from Python?
  • How do you generate a random number?
  • Which check should happen first?
  • How will your program decide whether the passenger is blocked, screened, or allowed?
  • What messages should the program print so the user understands what happened?
📌 SUCCESS CRITERIA
  • Your program uses at least one import.
  • Your program checks whether the airport is open.
  • Your program generates a random number only when needed.
  • Your program checks whether the number works exactly with 7.
  • Your output is clear and readable.
  • Your code is organised enough that you could explain it out loud.
📚 Where to find what modules can do (and what modules exist)

When you use import, you are bringing in tools that already exist in Python.

There are hundreds of built-in modules — you are not expected to memorise them.

🔎 Where to find available modules
  • Python Standard Library (official list):
    https://docs.python.org/3/library/
  • Search online:
    Try Python modules list or Python library random
  • Ask Python itself what exists (advanced later)
🧠 How to find what a module can do
  • Search the module name (e.g. Python random)
  • Use the official documentation
  • Use help() inside Python
# ============================================================
# USING PYTHON TO EXPLORE MODULES
# ============================================================

# Import a module
import random

# Ask Python what this module can do
help(random)

# Look at a specific function inside the module
help(random.randint)

# This shows:
# - what the function does
# - what inputs it needs
# - what it returns

Key idea: Real programmers don’t memorise modules — they look them up, test them, and learn as they go.

Stage 1: Using datetime

First, your program needs to know the current time.

Use the datetime import to get the current hour.

# ============================================================
# STAGE 1: GET THE CURRENT TIME
# ============================================================

# Import the datetime tool from Python
from datetime import datetime

# Get the current date and time right now
current_time = datetime.now()

# Pull out just the hour part
# Example: if the time is 2:45 pm, the hour will be 14
current_hour = current_time.hour

# Show the hour so we can test that it worked
print("Current hour:", current_hour)

# Next step:
# Write an if statement that checks whether the airport is open
# The airport is open from 6 to 22
Stage 2: Using random

If the airport is open, the program should generate a random number.

Use the random import to generate a whole number between 1 and 100.

# ============================================================
# STAGE 2: GENERATE A RANDOM NUMBER
# ============================================================

# Import Python's random tool
import random

# Generate a random whole number from 1 to 100
security_number = random.randint(1, 100)

# Show the number so we can test the program
print("Security number:", security_number)

# Next step:
# Work out how to test whether this number divides exactly by 7
Stage 3: Put the challenge together

Now combine the time check and the random check into one complete airport security system.

First
Check if the airport is open.
Second
If open, generate a random number.
Third
Check if the number works exactly with 7.
Finally
Print the result clearly.
# ============================================================
# AIRPORT SECURITY CHALLENGE
# ============================================================

# Import the tools you need
from datetime import datetime
import random

# ------------------------------------------------------------
# STEP 1: GET THE CURRENT HOUR
# ------------------------------------------------------------
current_time = datetime.now()
current_hour = current_time.hour

# Show the hour for testing
print("Current hour:", current_hour)

# ------------------------------------------------------------
# STEP 2: CHECK IF THE AIRPORT IS OPEN
# ------------------------------------------------------------
# The airport is open from 6 to 22
# Complete this if statement

if current_hour >= 6 and current_hour <= 22:
    print("Airport is open.")

    # --------------------------------------------------------
    # STEP 3: GENERATE A RANDOM SECURITY NUMBER
    # --------------------------------------------------------
    security_number = random.randint(1, 100)
    print("Security number:", security_number)

    # --------------------------------------------------------
    # STEP 4: CHECK THE NUMBER
    # --------------------------------------------------------
    # Write the logic here to decide:
    # - extra screening
    # - or allowed through

else:
    print("Airport is closed.")
Hints
Hint 1: Imports go near the top

Most Python programs put their imports near the beginning so it is easy to see which tools are being used.

Hint 2: Solve one part at a time

Get the time check working first. Only after that should you worry about the random number.

Hint 3: Think about exact division

You need to decide whether the security number can be divided by 7 exactly.

There is a neat operator in Python that helps with this. If you do not remember it yet, post your best attempt first.

Hint 4: Keep your output clear

Good programs tell the user what happened. Don’t just print a number. Print a message that explains the result.

💬 WHAT TO POST IN REPLY BELOW
  • your code
  • or your draft code
  • or a plain-English explanation of your logic
  • or a screenshot of your attempt
✅ REMEMBER

You do not need to get it perfect on the first go.

The goal is to think, test, improve, and explain your logic.