Module 19 — Python Projects
Putting everything together — from a number-guessing game to a full CRUD application.
Prerequisite: Module 18 — GUI Programming with Tkinter
After this lesson, you will be able to
- Plan a small project by breaking it into requirements and steps
- Build a complete number-guessing game end to end
- Know which concepts each project category is designed to practice
Concept & Syntax
Reading about Python and building with Python are different skills — projects are where lessons turn into ability. This module walks through one complete project in detail, then points you to the full Project Dashboard, which lists beginner, intermediate, and advanced projects along with a large capstone that combines nearly everything in this course.
# A good project always starts with a plain-language plan:
# 1. What does it do?
# 2. What information does it need?
# 3. What are the steps, in order?
# 4. What could go wrong, and how should it be handled?Examples
Walkthrough: Number Guessing Game — plan Very Easy
# Objective: the computer picks a secret number 1-100; the player guesses
# until they get it right, with "higher/lower" hints after each guess.
#
# Requirements:
# - Generate a random number
# - Accept repeated guesses
# - Give feedback after each guess
# - Count and report the number of attemptsWriting the plan in plain English before writing code is a habit worth building early — it turns a vague idea into a concrete checklist.
Walkthrough: Number Guessing Game — full code Real World
import random
secret = random.randint(1, 100)
attempts = 0
while True:
guess = int(input("Guess a number (1-100): "))
attempts += 1
if guess < secret:
print("Higher!")
elif guess > secret:
print("Lower!")
else:
print(f"Correct! It took you {attempts} attempts.")
breakThis combines a while loop, if/elif/else, input()/int(), and the random module — every one of them covered earlier in this course.
Extending the project Challenge
# Ideas to extend the game further, using concepts from this course:
# - Limit the player to 7 attempts (control flow)
# - Track high scores across games in a list (lists)
# - Save scores to a file between runs (file I/O)
# - Wrap it in a class called GuessingGame (OOP)
# - Build a Tkinter version with an Entry box (GUI)Real growth comes from extending a finished project, not just finishing it once — each idea above maps directly to an earlier module.
Visual Explanation
💡 Why does this work?
Read the concept explanation above again slowly, line by line — every keyword there maps directly onto a line of code in the examples. If it still doesn't click, re-run the traced example (if this lesson has one) one step at a time.
🔍 What happens internally? (advanced)
Under the hood, Python compiles your source into bytecode and runs it on a virtual machine (the CPython interpreter). Variables are names in a namespace dictionary pointing at objects in memory — which is exactly what the memory panel in the tracer above is showing you.
Common Mistakes
Trying to build every feature at once before testing anything makes bugs much harder to isolate.
# Writing the entire guessing game, GUI, file-saving, and
# high-score tracking all at once, then running it for the first time.# Get the core loop working and tested first.
# Then add ONE feature, test again, then add the next.- Start with the smallest version of a project that actually runs, then add features one at a time.
- Test after every meaningful change, not just at the very end.
- Re-read the project requirements before calling it 'done' — it's easy to forget one.
- Reuse functions from earlier modules rather than rewriting similar logic.
Exercise & Challenge
Exercise 1 — Predict the output
In the number-guessing game code above, what happens if the player's very first guess is exactly the secret number?
🏆 Challenge
Pick one extension idea from the examples above (attempt limit, high-score list, or file saving) and implement it on top of the base guessing game.
- Start from the working base game
- Add exactly one new feature
- Test that the base game still works after your change
💡 Need a hint?
An attempt limit just needs an if attempts >= 7: break check inside the loop.
🔍 Show a sample solution
import random
secret = random.randint(1, 100)
attempts = 0
max_attempts = 7
while attempts < max_attempts:
guess = int(input("Guess a number (1-100): "))
attempts += 1
if guess < secret:
print("Higher!")
elif guess > secret:
print("Lower!")
else:
print(f"Correct! It took you {attempts} attempts.")
break
else:
print(f"Out of attempts! The number was {secret}.")Quiz
Answer every question, then submit to see your score and explanations.
1. What's the recommended first step before writing any project code?
2. Why build the smallest working version of a project first?
Summary
- Every project benefits from a short written plan before any code is written.
- Build the simplest working version first, test it, then add features one at a time.
- The number-guessing game combines loops, conditionals, and input handling from earlier modules.
- The full Project Dashboard has beginner, intermediate, and advanced projects, plus a capstone.