Skip to content

Practice Projects

>Projects — cheat sheet

Reuse these small-program patterns to turn an idea into a working project one clear step at a time.

Plan the program

steps = ["get values", "calculate", "show result"]
Break a project into a short ordered plan.
result = 0
print(result)
Start with a tiny working version before adding features.
message = ""
if not message:
    print("Need a value")
Check simple invalid or missing data early.
total = 10
print(f"Total: {total}")
Show results with clear labels.

Number guessing game pattern

secret = 7
guess = 4
Keep the target and the current guess in named variables.
if guess == secret:
    print("Correct")
Compare a guess directly with the target.
if guess < secret:
    print("Too low")
else:
    print("Too high or correct")
Give feedback based on how two values compare.
attempts = 0
attempts += 1
Use a counter to track repeated tries.

Tip and bill splitter pattern

bill = 48.0
tip_rate = 0.15
tip = bill * tip_rate
Store each part of a calculation in a clear variable.
total = bill + tip
Build a final result from smaller results.
people = 3
share = total / people
Divide a total only after choosing the group size.
print(f"Each person pays ${share:.2f}")
Format money with two decimal places.

Word statistics pattern

text = "Python makes text useful"
words = text.lower().split()
Normalize and split text before analyzing it.
word_count = len(words)
Count words after splitting into a list.
letters = [letter for letter in text if letter.isalpha()]
Filter characters before counting letters.
counts = {}
for word in words:
    counts[word] = counts.get(word, 0) + 1
Use a dictionary to build a frequency count.

To-do list manager pattern

tasks = []
tasks.append("Practice Python")
Keep changing to-do items in a list.
for index, task in enumerate(tasks, start=1):
    print(index, task)
Display each task with a friendly number.
class Task:
    def __init__(self, title):
        self.title = title
        self.done = False
A class can group a task's data together.
def mark_done(task):
    task.done = True
Put one task action in a small named method or function.
All cheat sheets