Skip to content

Commit 8263271

Browse files
travisjneumanclaude
andcommitted
feat: flesh out SOLUTION.md for all 15 level-00 beginner exercises
Replace skeleton placeholders with complete, beginner-friendly solutions for exercises 01-first-steps through 15-putting-it-together. Every solution includes WHY-comments on every line, design decision tables, alternative approaches, common pitfalls for absolute beginners, and key takeaways connecting to future concepts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5bacd95 commit 8263271

File tree

15 files changed

+1714
-0
lines changed

15 files changed

+1714
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Solution: 01-first-steps
2+
3+
> **STOP** — Have you attempted this project yourself first?
4+
>
5+
> Learning happens in the struggle, not in reading answers.
6+
> Spend at least 20 minutes trying before reading this solution.
7+
> If you are stuck, try the [Walkthrough](./WALKTHROUGH.md) first — it guides
8+
> your thinking without giving away the answer.
9+
10+
---
11+
12+
13+
## Complete solution
14+
15+
This exercise is done in Python's **interactive mode** (the `>>>` prompt), not by writing a file. Here is what you should have typed and seen:
16+
17+
```python
18+
# Step 1: Open your terminal and type "python" to start interactive mode.
19+
# You should see the >>> prompt.
20+
21+
# Step 2: Try basic math.
22+
2 + 2 # WHY: This tests that Python is working — it should respond with 4
23+
10 - 3 # WHY: Subtraction works with the minus sign, just like on paper
24+
5 * 6 # WHY: The * symbol means multiply (the x key is used for variable names)
25+
100 / 4 # WHY: The / symbol means divide — Python gives you 25.0 (a decimal number)
26+
27+
# Step 3: Print a message.
28+
print("Hello, I am learning Python!") # WHY: print() displays text on screen — the quotes mark where the text starts and ends
29+
30+
# Step 4: Exit interactive mode.
31+
exit() # WHY: This tells Python you are done — it closes the interactive session
32+
```
33+
34+
If you ran the `exercise.py` file directly, here is what it does:
35+
36+
```python
37+
print("If you can see this, you successfully ran a Python file!") # WHY: Confirms the file ran — if you see this, Python found and executed the file
38+
print() # WHY: Prints a blank line to add visual spacing between sections
39+
print("Here is some math Python can do:") # WHY: Labels the section so you know what comes next
40+
print("2 + 2 =", 2 + 2) # WHY: Python calculates 2+2 and prints the label and result together
41+
print("10 - 3 =", 10 - 3) # WHY: Shows subtraction — the comma between items adds a space automatically
42+
print("5 * 6 =", 5 * 6) # WHY: Shows multiplication — * is the multiply symbol in programming
43+
print("100 / 4 =", 100 / 4) # WHY: Shows division — notice the result is 25.0 (decimal), not 25
44+
print() # WHY: Another blank line for visual breathing room
45+
print("You are off to a great start.") # WHY: Encouragement — learning to code is a big step
46+
```
47+
48+
## Design decisions
49+
50+
| Decision | Why | Alternative considered |
51+
|----------|-----|----------------------|
52+
| Use interactive mode first | Seeing instant results builds confidence — you type something, Python responds immediately | Could have started with writing a file, but that adds extra steps before seeing results |
53+
| Show math before text | Numbers are familiar to everyone — math gives instant proof that Python works | Could have started with print(), but math is more concrete and universal |
54+
| Use `*` for multiply and `/` for divide | These are the standard symbols in all programming languages — your keyboard does not have a x or / key for math | None — this is universal across programming |
55+
| Include `exit()` instruction | New users often get stuck in interactive mode, not knowing how to get back to their terminal | Could use Ctrl+D (Mac/Linux) or Ctrl+Z (Windows), but exit() works everywhere |
56+
57+
## Alternative approaches
58+
59+
### Approach B: Run the file directly instead of using interactive mode
60+
61+
```python
62+
# Save this in a file called first_steps.py and run it with: python first_steps.py
63+
print(2 + 2) # WHY: Same math, but written in a file instead of typed interactively
64+
print(10 - 3) # WHY: Every line runs automatically, top to bottom
65+
print(5 * 6) # WHY: You do not have to wait for each result — they all print at once
66+
print(100 / 4) # WHY: This is how you will write most Python code going forward
67+
print("Hello, I am learning Python!") # WHY: Files let you save and re-run your code
68+
```
69+
70+
**Trade-off:** Running a file is how you will work most of the time, but interactive mode is better for experimenting because you see each result immediately. Interactive mode is like a calculator; a file is like a recipe.
71+
72+
## What could go wrong
73+
74+
| Scenario | What happens | Prevention |
75+
|----------|-------------|------------|
76+
| Typing `python` and getting "command not found" | Python is not installed, or your terminal cannot find it | Revisit the setup guide (03_SETUP_ALL_PLATFORMS.md) and make sure Python is on your PATH |
77+
| Seeing `>>>` but not knowing what to do | You are in interactive mode — Python is waiting for you to type something | Type any math like `2 + 2` and press Enter. Type `exit()` to leave |
78+
| Forgetting the quotes around text in print() | You get a `NameError` because Python thinks the words are variable names, not text | Always wrap text in quotes: `print("Hello")` not `print(Hello)` |
79+
| Typing `print "Hello"` without parentheses | You get a `SyntaxError` — Python 3 requires parentheses around print | Always use `print("Hello")` with parentheses |
80+
| Pressing Enter after `python exercise.py` and nothing happens | You might be in the wrong folder — your terminal cannot find the file | Use `cd` to navigate to the folder containing exercise.py first |
81+
82+
## Key takeaways
83+
84+
1. **Python's interactive mode (`>>>`) is your playground** — use it to experiment, test ideas, and see instant results. You will use it throughout your learning.
85+
2. **Python does math with symbols you mostly know**`+` for add, `-` for subtract, `*` for multiply (not x), `/` for divide.
86+
3. **`print()` is how you make Python talk to you** — everything you want to display on screen goes inside `print()`. This is the foundation of every program you will write from here on.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Solution: 02-hello-world
2+
3+
> **STOP** — Have you attempted this project yourself first?
4+
>
5+
> Learning happens in the struggle, not in reading answers.
6+
> Spend at least 20 minutes trying before reading this solution.
7+
> If you are stuck, try the [Walkthrough](./WALKTHROUGH.md) first — it guides
8+
> your thinking without giving away the answer.
9+
10+
---
11+
12+
13+
## Complete solution
14+
15+
```python
16+
# Display the classic first-program message.
17+
print("Hello, world!") # WHY: This is the traditional first program in every language — it proves you can make the computer display text
18+
19+
# Print a custom message to show you can change the text.
20+
print("My name is Python and I do what you tell me.") # WHY: Demonstrates that you can put any text inside the quotes
21+
22+
# Print a number — no quotes needed for numbers.
23+
print(42) # WHY: Numbers do not need quotes because Python already knows they are numbers, not commands
24+
25+
# Print a math result — Python calculates it first, then displays the answer.
26+
print(7 + 3) # WHY: Python does the math (7+3=10) and then prints the result — you never see "7 + 3", just "10"
27+
28+
# Print text and a calculated number together using a comma.
29+
print("The answer is", 6 * 7) # WHY: The comma lets you mix text and numbers — Python adds a space between them automatically
30+
31+
# Print a blank line to create visual spacing.
32+
print() # WHY: An empty print() outputs a blank line — useful for making output easier to read
33+
34+
# Show that single quotes and double quotes both work.
35+
print('Single quotes work too.') # WHY: Python treats 'text' and "text" exactly the same — use whichever you prefer
36+
print("Double quotes also work.") # WHY: Most programmers pick one style and stick with it — double quotes are more common in Python
37+
```
38+
39+
## Design decisions
40+
41+
| Decision | Why | Alternative considered |
42+
|----------|-----|----------------------|
43+
| Start with `"Hello, world!"` | This is a tradition going back to 1978 — nearly every programmer's first program prints this message | Could use any message, but this connects you to millions of other learners |
44+
| Use double quotes for strings | Double quotes are the most common convention in Python and many other languages | Single quotes work identically — `'Hello'` and `"Hello"` do exactly the same thing |
45+
| Show commas for mixing text and numbers | Commas are the simplest way to combine different types in `print()` — no conversion needed | Could use f-strings (covered in Exercise 06), but commas are simpler for beginners |
46+
| Include `print()` with no arguments | Blank lines make output much easier to read, and this teaches that print() can be called empty | Could skip blank lines, but cluttered output is harder to understand |
47+
48+
## Alternative approaches
49+
50+
### Approach B: Using f-strings (a preview of Exercise 06)
51+
52+
```python
53+
name = "Alice" # WHY: Store your name in a variable so you can reuse it
54+
age = 25 # WHY: Store a number in a variable
55+
print(f"Hello, my name is {name}!") # WHY: f-strings let you insert variables directly into text — the f before the quote enables this
56+
print(f"I am {age} years old.") # WHY: {age} gets replaced with the value 25 when Python runs this line
57+
print(f"Next year I will be {age + 1}.") # WHY: You can even do math inside the curly braces
58+
```
59+
60+
**Trade-off:** f-strings are more powerful and readable than commas, but they require understanding variables first (Exercise 04). For this exercise, plain `print()` with commas is the right starting point.
61+
62+
### Approach C: Using string concatenation (joining strings with +)
63+
64+
```python
65+
print("Hello" + ", " + "world" + "!") # WHY: The + operator glues strings together — but you must handle spaces yourself
66+
print("The answer is " + str(42)) # WHY: You cannot use + to join a string and a number — str() converts the number to text first
67+
```
68+
69+
**Trade-off:** Concatenation with `+` requires you to manually add spaces and convert numbers to strings with `str()`. Commas handle this automatically. Concatenation is useful when you need precise control over spacing.
70+
71+
## What could go wrong
72+
73+
| Scenario | What happens | Prevention |
74+
|----------|-------------|------------|
75+
| Mismatched quotes: `print("Hello')` | `SyntaxError` — Python sees a double quote opening but a single quote closing, and they do not match | Always use the same quote type to open and close: `"Hello"` or `'Hello'` |
76+
| Forgetting the parentheses: `print "Hello"` | `SyntaxError` — Python 3 requires parentheses around everything you print | Always write `print("text")` with parentheses |
77+
| No quotes around text: `print(Hello)` | `NameError: name 'Hello' is not defined` — Python thinks Hello is a variable name, not text | Wrap text in quotes so Python knows it is a string: `print("Hello")` |
78+
| Forgetting the closing quote: `print("Hello)` | `SyntaxError: unterminated string literal` — Python reached the end of the line without finding the closing quote | Always close your quotes — most code editors highlight unclosed strings |
79+
| Trying to use `+` with a string and number: `print("age: " + 25)` | `TypeError` — Python refuses to glue text and numbers together with `+` | Use a comma instead: `print("age:", 25)` or convert: `print("age: " + str(25))` |
80+
81+
## Key takeaways
82+
83+
1. **`print()` is your primary tool for seeing what your program does** — every time you want to check a value, display a result, or show a message, you will use `print()`. It is the most used function in all of Python.
84+
2. **Strings (text) must always be wrapped in quotes** — without quotes, Python thinks your words are commands or variable names. Quotes are how Python tells the difference between code and data.
85+
3. **You can mix text and numbers in `print()` using commas** — Python automatically adds a space between each item. This simple technique carries you through most beginner programs before you learn fancier methods like f-strings.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Solution: 03-your-first-script
2+
3+
> **STOP** — Have you attempted this project yourself first?
4+
>
5+
> Learning happens in the struggle, not in reading answers.
6+
> Spend at least 20 minutes trying before reading this solution.
7+
> If you are stuck, try the [Walkthrough](./WALKTHROUGH.md) first — it guides
8+
> your thinking without giving away the answer.
9+
10+
---
11+
12+
13+
## Complete solution
14+
15+
```python
16+
# Step 1: Print a greeting.
17+
print("Welcome to your first Python script!") # WHY: This is the first line Python runs — it tells the user the script has started
18+
19+
# Step 2: Do some math and print the result.
20+
print("Let me calculate something for you...") # WHY: Gives context for what is about to happen — good programs tell you what they are doing
21+
print("If you have 24 hours in a day and 7 days in a week:") # WHY: Explains the calculation in plain English before showing the math
22+
print("That is", 24 * 7, "hours in a week.") # WHY: Python calculates 24*7=168 and prints it between the two text strings
23+
24+
# Step 3: Print a blank line for readability.
25+
print() # WHY: A blank line separates sections visually — without it, all the text runs together
26+
27+
# Step 4: Print a closing message.
28+
print("This script ran from top to bottom.") # WHY: Reinforces the key lesson — Python executes line 1, then line 2, then line 3, and so on
29+
print("Every line executed in order.") # WHY: There are no jumps or skips (yet) — the order in the file IS the order of execution
30+
print("That is how all Python scripts work.") # WHY: This top-to-bottom flow is called "sequential execution" and is the foundation of all programs
31+
```
32+
33+
## Design decisions
34+
35+
| Decision | Why | Alternative considered |
36+
|----------|-----|----------------------|
37+
| Write commands in a file instead of interactive mode | Files let you save, edit, and re-run your code — interactive mode loses everything when you close it | Interactive mode (Exercise 01) is good for experimenting, but real programs live in files |
38+
| Use comments (lines starting with #) | Comments explain WHY the code does something — they are notes for humans that Python ignores entirely | Could write code without comments, but then you would forget what each line does tomorrow |
39+
| Calculate `24 * 7` inline inside print() | Keeps the example simple — no variables needed yet (those come in Exercise 04) | Could store the result in a variable first, but that adds a concept not yet introduced |
40+
| End with a message about sequential execution | The most important lesson is that scripts run top-to-bottom — this makes the lesson explicit | Could leave it implicit, but beginners benefit from having concepts stated directly |
41+
42+
## Alternative approaches
43+
44+
### Approach B: A personal introduction script
45+
46+
```python
47+
# My personal introduction script
48+
# This file tells the world about me.
49+
50+
print("=== About Me ===") # WHY: The === creates a visual header — it makes the output look organized
51+
print() # WHY: Blank line after the header for readability
52+
print("Name: Alice") # WHY: Each print() is one line of output — put one fact per line
53+
print("Hobby: Learning Python") # WHY: You can put any text you want — make it personal
54+
print("Fun fact: I just ran my first script!") # WHY: This is YOUR script — personalize it
55+
print() # WHY: Spacing before the closing line
56+
print("Script complete!") # WHY: A clear ending tells you the script finished successfully
57+
```
58+
59+
**Trade-off:** Both scripts teach the same concept (top-to-bottom execution). Making it personal helps you feel ownership over the code — it is YOUR script, not just an exercise you copied.
60+
61+
### Approach C: A script with commented-out lines
62+
63+
```python
64+
print("Line 1: I will print") # WHY: This line runs because it is valid Python code
65+
# print("Line 2: I am commented out") # WHY: The # at the start makes Python skip this entire line
66+
print("Line 3: I will also print") # WHY: Python skips the comment and continues to the next real line
67+
```
68+
69+
**Trade-off:** This version directly teaches commenting and un-commenting. Try adding and removing the `#` to see lines appear and disappear from the output.
70+
71+
## What could go wrong
72+
73+
| Scenario | What happens | Prevention |
74+
|----------|-------------|------------|
75+
| Running `python exercise.py` from the wrong folder | `FileNotFoundError` — Python cannot find the file because you are not in the right directory | Use `cd` to navigate to the folder first, then run the command. The terminal prompt usually shows your current folder |
76+
| Misspelling the filename: `python exorcise.py` | `FileNotFoundError` or `No such file or directory` — the filename must match exactly | Check the spelling. Tab-completion (pressing Tab after typing a few letters) can auto-fill the filename |
77+
| Forgetting to save the file before running | Python runs the last saved version, not what is currently on screen | Always save (Ctrl+S) before running. Some editors auto-save, but do not rely on it |
78+
| Adding code with wrong indentation | `IndentationError` — Python is strict about spacing at the beginning of lines | For now, start every line at the very left edge (no spaces before print). Indentation becomes important in Exercise 08 |
79+
| Using a `.txt` extension instead of `.py` | The file might still run, but your editor will not give you Python syntax highlighting, making it harder to read | Always name Python files with the `.py` extension |
80+
81+
## Key takeaways
82+
83+
1. **A Python script is just a text file full of commands that run top-to-bottom** — the order you write them is the order Python executes them. This is the most fundamental concept in programming: you are writing a sequence of instructions.
84+
2. **Comments (lines starting with #) are notes for humans** — Python ignores them completely. Use comments to explain what your code does and why. Your future self will thank you when you re-read your code weeks later.
85+
3. **The ability to save code in a file changes everything** — unlike interactive mode, files let you build up complex programs, edit them, share them, and run them as many times as you want. Every real program you use (websites, apps, games) started as files of code like this one.

0 commit comments

Comments
 (0)