topskill.dev
CoursesTracks
0
All courses/Python Basics: The Lantern AtlasChoose a Gate Signal
Level 3: Gate Trials — Decisions and Loops
4 / 12
← Python Basics: The Lantern Atlas
○Level 1: Spawn Camp○Demo: Light the Camp Message○Exercise: Open the Lantern Map○Code Comments○Demo: Name a Map Location○Exercise: Label a Beacon○Variable Types○Demo: Inspect Lantern Types○Exercise: Pack Starting Supplies○Optional: Set up Python Locally✦Module Quiz
○Demo: Divide Beacon Shards○Exercise: Price a Cache Route○Demo: Format a Gear Label○Exercise: Format Forge Readouts○Demo: Convert Shard Text○Exercise: Convert Charge Readings○Demo: Read a Pathfinder Name○Project: Build Adi’s Gear HUD✦Module Quiz
○Demo: Compare Workshop Supplies○Exercise: Check Gate Supplies○Demo: Choose a Lit Route●Choose a Gate Signal○Demo: Pulse a Beacon with while○Exercise: Recharge the Beacon○Demo: Mark a Route with range○Exercise: Label Even Patrols○Demo: Skip a Hazard, Stop at a Gate○Exercise: Cross Safe Tiles○Project: Unlock the Exit Gate✦Module Quiz
○Define a Beacon Ability: Demo○Exercise: Activate a Beacon○Pass Energy and Return a Result: Demo○Exercise: Combine Beacon Energy○Default Ability Marks: Demo○Exercise: Name a Beacon Ability○Local Energy Scope: Demo○Exercise: Spend Local Energy○Project: Build an Ability Loadout✦Module Quiz
○Read a Rune Code: Demo○Exercise: Read Rune Edges○Slice a Cavern Route: Demo○Exercise: Decode Route Fields○Clean a Rune Message: Demo○Exercise: Decode a Rune Notice○Format a Route Card: Demo○Exercise: Write a Decoded Route Sign✦Module Quiz
○Index a Gear List: Demo○Exercise: Build a Gear Queue○Change a Gear List: Demo○Exercise: Repair the Loadout○Slice a Ridge Route: Demo○Exercise: Pack for Checkpoints○Read a Fixed Checkpoint Record: Demo○Exercise: Read an Exit Checkpoint✦Module Quiz
○Read an Atlas Map Card○Exercise: Update a Map Entry○Loop Through Beacon Map Entries○Exercise: Count Cache Marks○Count Unique Atlas Stops○Exercise: Compare Atlas Routes○Demo: Summarize Beacon Finds○Exercise: Build the Atlas Treasure Index✦Module Quiz
○Recover a Faded Beacon Reading○Exercise: Label Beacon Charge○Demo: Write a Shrine Save○Exercise: Save a Beacon Signal○Mini Project: Restore the Save Shrine✦Module Quiz
○Demo: Calculate Beacon Capacity○Exercise: Calculate Lantern Capacity○Demo: Import a Local Beacon Rule○Exercise: Import a Shrine Rule○Demo: Follow a Dotted Package Import○Exercise: Read an Atlas Record✦Module Quiz
○Echo Tower: The Base Case○Echo Tower: Sum the Signals○Echo Tower: Tune the Frequencies○Echo Tower: Select Beacon Labels✦Module Quiz
○Exit Gate: Reading Object Vocabulary○Final Game Mission: Open the Exit Gate✦Module Quiz

Choose a Gate Signal

A gate uses its remaining charge to choose a signal: Sealed, Flickering, or Open. You will add each branch separately so you can check one case before writing the next.

You have used comparisons to get True or False. An if statement uses that result to choose what happens next.

See how a choice works

This lantern uses a different set of values. Predict its message, then press Run below.

python
wicks = 2
if wicks == 0:
    message = "Dark"
elif wicks < 3:
    message = "Dim"
else:
    message = "Bright"
print(message)

The result is Dim. Follow the checks from top to bottom:

  • if wicks == 0: false, so Python skips "Dark".
  • elif wicks < 3: true, so Python chooses "Dim".
  • else: skipped because a previous branch already matched.

Only one branch runs. Once Python finds a true condition, it skips the remaining branches in that chain.

Put a colon at the end of each branch heading. Indent its assignment by four spaces. Keep if, elif, and else aligned; else has no condition.

Set up your gate

In main.py, the charge is already set to 2. The "Not set" value is a temporary message for cases you have not written yet. Keep that assignment, add your branches below it, and leave print(gate_signal) at the end with no indentation.

Build one branch at a time. Press Submit after each task: its matching check can pass even while later branches are unfinished.

Your Task

  1. Add an if charge_left == 0: branch that sets gate_signal to "Sealed".
  2. Add an elif charge_left < 4: branch that sets gate_signal to "Flickering".
  3. Add an else: branch that sets gate_signal to "Open".

Try each route

Change only the supplied charge_left value and press Run:

After completingTry this chargeYou should see
Task 10Sealed
Task 22Flickering
Task 34Open

While a branch is unfinished, seeing Not set for its charge is expected. Restore charge_left to 2 when you finish, then Submit to check all three routes.

Notice the boundary: 3 is still Flickering, but 4 is Open. Zero must be checked first because it also satisfies < 4.

The gate now has a message for each charge range. Next, you will repeat an action with a loop: first counting beacon pulses, then recharging a beacon.

Hint 1
1 / 3
HINT 1

Keep gate_signal = "Not set" above your branches so unfinished cases still run.

HINT 2

Align if, elif, and else. End each branch heading with a colon and indent its assignment by four spaces.

HINT 3

Check zero first. Zero is also less than four, but Python runs only the first matching branch.

Files
  • ⋄main.py
Loading editor…
Press Run to execute your code.