Past Lesson Note

This note is from 1 month ago. You're viewing content from a previous lesson.

Daily Note for September 21, 2026 Past Lesson

Time: 90 minutes
You will need: Python, your code editor, and your weapon generator from last lesson for reference.

Last lesson, you modified an existing procedural weapon generator. Today, you will create a new generator in a new Python file.

Your program will generate a treasure with a name, appearance, value, magical effect, and history. You may use the templates below and look at last lesson’s code, but you must assemble and test your own program.

Procedural generation means using data and rules to automatically create content. Your lists provide the possibilities, random selections create variety, and your conditions make the results follow rules.

By the end of the lesson, you should have a program that produces descriptions like this:

You discovered a mysterious silver crown.
It was found in an abandoned tower.
It is worth 82 gold coins.
Magical effect: It whispers warnings when danger approaches.
History: A missing queen once owned this treasure.

Your output will vary because your program makes random choices.


Your lesson schedule

Time Task Checkpoint
0–10 minutes Create and run your file A welcome message appears
10–25 minutes Generate a treasure name Three randomly selected words appear
25–40 minutes Add a location and value A location and number appear
40–55 minutes Add magical rules The effect matches the adjective
55–65 minutes Add a history function A randomly selected history appears
65–75 minutes Finish the description One complete description appears
75–85 minutes Test and improve Test results are recorded
85–90 minutes Submit and reflect Your file and answers are submitted

Work through the tasks in order. Run your program after each small change.


Task 1: Create your file — 10 minutes

  1. Create a new file called treasure_generator.py.

  2. Add a comment containing your name.

  3. Import Python’s random module.

  4. Display a welcome message.

  5. Save and run your file.

Use this starting template:

# Treasure generator
# Name:

import random

print("Welcome to the treasure generator!")

Checkpoint: Your program runs and displays the welcome message.

If it does not run, check that you saved the file with the .py extension and that the quotation marks and parentheses are paired.


Task 2: Generate a treasure name — 15 minutes

Your treasure name will contain three parts:

adjective + material + treasure type

For example:

cursed wooden ring

A. Create three lists

Place these lists below the import and above the welcome message:

treasure_adjectives = ["ordinary", "glowing", "cursed", "mysterious"]

treasure_materials = ["gold", "silver"]

treasure_types = ["ring", "crown"]

Make the following changes:

  • Add at least three more materials, giving you at least five.

  • Add at least three more treasure types, giving you at least five.

  • Keep the four adjectives exactly as written. You will use them in Task 4.

Possible materials include wood, glass, iron, crystal, and bone. Possible treasure types include a key, necklace, cup, mirror, and coin.

Every item must be inside quotation marks. Separate items with commas.

B. Select one item from each list

Add this line below your lists:

selected_adjective = random.choice(treasure_adjectives)

Write two similar lines yourself:

  • Select from treasure_materials and store the result in selected_material.

  • Select from treasure_types and store the result in selected_type.

C. Display the name

Below the welcome message, add:

print("You discovered a", selected_adjective, selected_material, selected_type)

Run your program three times.

Checkpoint: Your program displays a treasure name made from three selected words. Some words may repeat between runs; that is normal.

Answer in a comment at the bottom of your file:

# Task 2: What is the difference between treasure_types and selected_type?
# Answer:

Task 3: Add a location and value — 15 minutes

A. Create possible locations

Add a list called treasure_locations alongside your other lists.

It must contain at least five locations. Write each location so it completes this sentence:

It was found in ______.

Examples:

  • "an abandoned tower"

  • "a dragon's cave"

  • "a locked chest"

Select one location and store it in a variable called selected_location.

Use your random.choice() lines from Task 2 as a pattern.

B. Generate a value

Use random.randint() to generate a whole number:

treasure_value = random.randint(10, 100)

This selects a whole number from 10 to 100, including both endpoints.

C. Display both results

Add two output lines below your treasure name:

print("It was found in", selected_location)
print("It is worth", treasure_value, "gold coins.")

Checkpoint: Your output includes a treasure name, a location, and a value between 10 and 100.

Answer in comments:

# Task 3: Which function selects an item from a list?
# Answer:

# Task 3: Which function generates a random whole number?
# Answer:

Task 4: Make the magic follow rules — 15 minutes

Randomness creates variety, but rules make a generator more believable.

The treasure’s magical effect must depend on its adjective.

Selected adjective Required behaviour
ordinary The treasure has no magical power
glowing The treasure produces light
cursed The treasure causes a problem for its owner
mysterious The treasure behaves in an unusual or unexplained way

A. Create the conditions

Place this code after your random selections and before your output:

if selected_adjective == "ordinary":
    magical_effect = "It has no magical power."
elif selected_adjective == "glowing":
    magical_effect = "Replace this with your own description."
elif selected_adjective == "cursed":
    magical_effect = "Replace this with your own description."
else:
    magical_effect = "Replace this with your own description."

Replace all three placeholder descriptions with your own ideas.

In this program, the else branch handles "mysterious" because it is the only remaining adjective.

Notice:

  • == compares two values.

  • = assigns a value to a variable.

  • Each condition ends with a colon.

  • Each assignment inside a branch is indented by four spaces.

B. Display the effect

Add this to your output:

print("Magical effect:", magical_effect)

Checkpoint: A glowing treasure produces light, a cursed treasure causes trouble, and an ordinary treasure has no magical power.

C. Explain a mistake

Suppose someone writes:

if treasure_adjectives == "glowing":

Explain why this does not check whether the selected treasure is glowing.

# Task 4: Why must we compare selected_adjective rather than treasure_adjectives?
# Answer:

Task 5: Create a history function — 10 minutes

A function lets you give a name to a task and run that task when needed.

You will create a function that chooses and returns one treasure history.

A. Define the function

Place this function below import random, before the rest of your program:

def generate_history():
    histories = [
        "A missing queen once owned this treasure.",
        "A fisherman discovered it inside an enormous fish."
    ]
    return random.choice(histories)

Add at least three more histories, giving you at least five.

Each history should be a complete sentence. Keep every history inside the list and separate the strings with commas.

B. Call the function

After your other selections, add:

selected_history = generate_history()

C. Display the result

Add this to your output:

print("History:", selected_history)

Checkpoint: Your output includes one history selected by your function.

Answer in a comment:

# Task 5: What does return send back to the code that called this function?
# Answer:

Task 6: Finish your generator — 10 minutes

Arrange your program in this order:

Order What belongs here
1 Name comment and import random
2 The generate_history() function
3 Lists of adjectives, materials, treasure types, and locations
4 Random selections, value generation, and the history function call
5 Conditions that determine the magical effect
6 Output statements
7 Your written answers and testing comments

Python executes the statements in your file from top to bottom. A variable must receive a value before you use it.

Check that your final output includes:

  • A treasure name containing an adjective, material, and type.

  • A location.

  • A value in gold coins.

  • A magical effect that matches the adjective.

  • A history.

Improve your presentation by adding a title and a blank line:

print()
print("YOUR TREASURE")
print()

Checkpoint: Your program produces one complete, readable treasure description without errors.


Task 7: Test your program deliberately — 10 minutes

Running a random generator repeatedly does not guarantee that every branch will be tested.

To test a specific adjective, temporarily replace:

selected_adjective = random.choice(treasure_adjectives)

with:

selected_adjective = "ordinary"

Run the program and check the effect. Repeat with "glowing", "cursed", and "mysterious".

Record your results in comments:

# TEST RESULTS
# ordinary: no magical power. Pass or fail:
# glowing: produces light. Pass or fail:
# cursed: causes a problem. Pass or fail:
# mysterious: unusual or unexplained effect. Pass or fail:

After testing, restore the random selection:

selected_adjective = random.choice(treasure_adjectives)

Run your finished generator five times. Check for missing information, spelling mistakes, or errors.

Final testing question:

# Why is temporarily selecting each adjective a better test
# than hoping random.choice() eventually selects all four?
# Answer:

Task 8: Submit your work — 5 minutes

Submit via email:

  1. Your completed treasure_generator.py file, including your answers and test results.

  2. One screenshot or copied example of your program’s output.

Add these final reflections at the bottom of your file:

# REFLECTION
# One thing I understand better now:
# One problem I encountered and how I addressed it:
# One feature I would add next:

If your program is unfinished, submit what you have. Add a comment explaining what works and where you became stuck.


Help if you get stuck

Problem What to check
SyntaxError Look for missing quotes, commas, brackets, parentheses, or colons. Also check the line above the reported error.
IndentationError Check the spaces inside your function and conditional branches.
NameError Check variable spelling and whether the variable was assigned before it was used.
The output shows a whole list Print the selected variable, such as selected_type, rather than the list, such as treasure_types.
The magical effect does not match Check that your condition compares selected_adjective with the correct string.
A result repeats Random choices can repeat. Repetition alone does not mean the program is broken.

If you are still stuck:

  1. Read the error message.

  2. Find the line number it identifies.

  3. Compare that section with the relevant template.

  4. Change one thing.

  5. Run the program again.


Finished early? Choose an extension

Complete and test the main tasks before attempting these.

Extension Instructions How to check it
Add another adjective Add a fifth adjective and give it its own magical effect. Update the conditions so "mysterious" still works correctly. Temporarily select each adjective and check its effect.
Make material affect value Add 50 gold coins when the selected material is "gold". Apply this rule before displaying the value. Temporarily select gold; the resulting value should be 60–150.
Add a curse strength When the treasure is cursed, generate a curse strength from 1 to 5 and display it. Force a cursed treasure, then an ordinary treasure. Only the cursed one should show a strength.
Create five treasures Put the generation and output steps inside a loop that runs five times. Keep the function definition outside the loop. Confirm that five complete descriptions appear and random selections happen inside the loop.

Optional mathematical challenge: Using your actual list lengths, calculate how many adjective–material–type names your generator can create. Ignore locations, values, effects, and histories. Show your calculation in a comment.