You awaken in a pixelated world — part Legend of Zelda, part Final Fantasy. Your quest: master the for-loop with numbers so you can forge experience tables, count coins, and design power-up sequences like the heroes of the NES era.
In the Kingdom of Pythonia, every adventurer needs one spell:
range() — the loop generator.
It’s the code equivalent of a dungeon crawl counter:
it tells Python how many rooms to walk through, how many enemies to fight, or how many levels to climb.
In story terms, range() is your path through the dungeon.
It tells Python where to start, where to stop, and how fast to move.
The first number (1) is where the dungeon starts.
The second number (5) is one room past the end (Python stops before it).
So range(1, 5) means 1 → 2 → 3 → 4.
That “off-by-one” rule keeps the code running just the right number of times.
The third value in range(start, stop, step) controls how far the loop moves each turn.
Your hero is hopping across numbered warp tiles from 0 to 10 — but only landing on every other one. That third number (2) is your “jump distance.” It tells Python to skip ahead two spaces at a time.
Explanation:
Start = 0
Stop before = 10
Step = 2
Output: 0, 2, 4, 6, 8
When you don’t specify where to start, Python automatically begins counting at 0 — like an NES score counter starting from zero lives. It runs five times (0 → 4), giving you five total steps.
Explanation:
Only one number = how many times to loop (5).
Python assumes you start at 0 and step by 1.
Output: 0, 1, 2, 3, 4.
This is the fun short-cut! We just need 1 value and we're good to go!
We can use list( ) to convert range( ) output into a list!!
Every good adventurer keeps track of their stats — the strongest hit, the weakest spell, and the total damage dealt after a long battle. Python gives you three built-in spells for that kind of analysis:
min() → Finds the lowest number in your list — like checking your weakest attack.
max() → Finds the highest number — your ultimate critical hit.
sum() → Adds everything together — your total XP, gold, or magic energy.
These functions scan through your list automatically and report back the result — no loops needed, no math spells memorized. They’re fast, simple, and perfect for tracking your progress in any numerical quest.
The crystals are dim. The Four Warriors of Light stand before the ancient Spell Forge deep beneath Castle Coneria. The court mage, Matoya, beckons you closer.
“Heroes,” she rasps, “your journey will be long. You’ll need to prepare your spells—carefully balanced, numerically aligned, and infused with arcane energy.”
Your quest tonight: learn to generate lists of magical power using range(), store them in variables, and calculate their total energy output before the great battle.
Create and manage lists of spell charges and mana crystals using for-loops and the range() function.
You’ll:
Generate two lists of magical power levels.
Sum the total “power energy” for each.
Present your results in a beautiful report fit for the Mage’s Guild.
Every spell charge grows stronger with each level learned.
Let’s generate levels 1–10 and calculate the total spell energy at each level.
Every Level, your spell power grows by 10% per level
Remember, you're multiplying the last level by 10% (or .10)
BONUS: Get This to display nicely to the nearest whole number:
See if you remember how to properly use int( ) to CAST it to a nice number!!!
Mana crystals are rarer and hold more energy per level
We’ll use a different scale and interval to show how we can manipulate range().
These crystals don’t just sit there—their energy rises steadily each time you infuse them with mana from the elemental altars.
At Level 1, the first crystal flickers at a base of 50 MP.
Each new level adds +5 MP energy, so by Level 10, your forge room will be blazing with power.
sum(spell_charges) reveals how much raw energy is stored in your spell scrolls.
sum(mana_crystals) measures the total magical essence trapped within the glowing gems.
Your next task is to combine the power of each list to determine the total magical energy they contain. This is the moment when your scattered values become a single, quantifiable force — the same kind of numeric calculation that fuels spell damage, HP totals, and XP progression behind every RPG ever made.
You’ll call upon the sum() spell — one of the simplest yet most powerful functions in Pythonia.
It sweeps through your list, adding every value together and returning a single total — your final energy output.
The crystals are glowing. The spell scrolls shimmer with stored energy. It’s time to assemble all your magical data — spell charges, mana crystals, and total energy readings — into a single, polished Arcane Status Report fit for the halls of Coneria Castle.
In this final challenge, you’ll use Python’s string formatting functions — ljust(), rjust(), and center() — to align your table neatly without symbols or padding clutter.
Think of it like arranging your inventory screen in a vintage RPG: clean, balanced, and satisfying.
Build a list of cargo weights (10 numbers between 1 and 100—make them up or ask a party member).
Compute quick stats with Python’s built-in “analysis spells”:
Heaviest cargo item → max()
Lightest cargo item → min()
Total cargo weight → sum()
Average cargo weight → sum(...) / len(...)
Present everything in a clean, NES-style report (use ljust, rjust, center for the vibe).
No conditionals, no while loops—just lists, loops, and stats. Exactly the kind of math the game engine was doing behind the scenes in 1987.
ADVANCED TASK: YOU MUST IMPLEMENT THIS!!!
Prompt the user to see how many cargo items they want to enter
Sample Output
Cid slams a clipboard onto the control console. “Alright, apprentice! Numbers are good, but the crew can’t tell one crate from another! I need an item manifest—names and weights—logged before we hit the next town!”
Your mission:
upgrade your program to track item names alongside their weights, then print the full cargo report so the crew can see which item is which.
A list comprehension lets you take what would normally be a multi-line loop that builds a list, and condense it into a single, clear, and powerful statement.
Think of it like casting “Mass Append” — instead of looping one item at a time,
You write the pattern once, and Python automatically creates every item in the list.
Here's The "Old Way" - Straight forward multi-line code to add these values to our list. This is what the code generates:
The same values are still generated, but we do it in 1 line. It's harder to read in some cases, but people do this for efficiency. Pick which way you like, but know both!!