Python

Python projects for beginners: three small programs with complete code

Build three beginner Python projects with complete code: a study tracker, quiz report and CSV stock checker. Check the output, then extend each one.

Good Python projects for beginners have a small input, a clear rule and an output you can check. Start with a study-time tracker, then build a quiz report and a CSV stock checker. Together they practise lists, dictionaries, loops, conditions and reading tabular data, without installing extra packages.

Each project below has complete source code, its expected output and an exercise to make it your own. All names and datasets are invented for teaching. The examples were rechecked with Python 3.12.14.

If you have never written Python, start with the free lesson Run your first Python code. If you can already use variables and a loop, choose a project and run it now.

Choose your first project

ProjectWhat you buildSkills you practiseA result you can check
Study trackerMinutes studied per topicLists, dictionaries, loops, totals60 Python minutes and 80 overall
Quiz reportScores with unanswered questionsNested dictionaries, strings, conditionsAsha scores 2/4 with one blank
CSV stock checkerItems that need reorderingCSV rows, integer conversion, boundariesNotebooks and Folders need attention

In this article:

Set up and run the code

Use Python 3 in an editor, a terminal or a notebook. These projects use only Python's standard library, which is the collection of tools included with Python.

Copy one project's complete code into a file with the suggested name. Run it from the same folder. For the first project:

python study_tracker.py

Some systems use python3 instead of python. In a notebook, paste the code into a cell and run the cell. The Python environments lesson explains how the interpreter and your project folder fit together.

Project 1: study-time tracker

The task: given a list of study sessions, report the minutes spent on each topic and the total across all topics.

Store each session as a dictionary with a topic and a duration. A list holds the sessions in order. Save this as study_tracker.py:

sessions = [
    {"topic": "Python", "minutes": 25},
    {"topic": "Statistics", "minutes": 20},
    {"topic": "Python", "minutes": 35},
]

minutes_by_topic = {}
for session in sessions:
    topic = session["topic"]
    minutes_by_topic[topic] = minutes_by_topic.get(topic, 0) + session["minutes"]

for topic, minutes in sorted(minutes_by_topic.items()):
    print(f"{topic}: {minutes} minutes")

print(f"Total: {sum(minutes_by_topic.values())} minutes")
assert sum(minutes_by_topic.values()) == 80

Expected output:

Python: 60 minutes
Statistics: 20 minutes
Total: 80 minutes

The first Python session contributes 25 minutes; the second adds 35, giving 60. Statistics contributes 20, so the overall total is 80.

The useful line is minutes_by_topic.get(topic, 0). It reads the existing total, or starts at zero when a topic appears for the first time. Sorting the dictionary's items makes the report's order predictable. The final assert checks the known total for this particular dataset; a failed assertion stops the program.

Try it yourself: add a 15-minute Data Tools session. The new total should be 95 minutes, and Data Tools should appear as a separate topic. Update the assertion to the new expected total. Then reject negative durations rather than subtracting them from study time.

If the data structure is unfamiliar, study lists and dictionaries, then run this project again. Those lessons lead into the Python track's quizzes when you sign in.

Project 2: quiz result report

The task: mark a small multiple-choice quiz, accepting upper- or lowercase answers and reporting blanks separately. Every question is worth one mark, and a blank earns no mark.

The answer key and submissions are made up for this example; they are not taken from SchoolWhool course quizzes. Save this as quiz_report.py:

answer_key = {"q1": "b", "q2": "a", "q3": "c", "q4": "b"}
submissions = {
    "Asha": {"q1": "B", "q2": "a", "q3": "a"},
    "Ben": {"q1": "b", "q2": "a", "q3": "c", "q4": "b"},
}

for name, answers in submissions.items():
    correct = 0
    unanswered = 0
    for question, expected in answer_key.items():
        answer = answers.get(question, "").strip().lower()
        if answer == "":
            unanswered += 1
        elif answer == expected:
            correct += 1
    total = len(answer_key)
    percent = correct / total * 100
    print(f"{name}: {correct}/{total} ({percent:.0f}%), unanswered: {unanswered}")

Expected output:

Asha: 2/4 (50%), unanswered: 1
Ben: 4/4 (100%), unanswered: 0

The program loops over the answer key, so a missing question remains part of the denominator. Asha answers two questions correctly, answers one incorrectly and leaves one blank. Her score is therefore 2 out of 4, or 50%, rather than 2 out of the 3 she attempted.

Calling strip().lower() removes surrounding whitespace and standardises case. The rules here assume each submitted answer is a string. A real form would also validate the submitted types and allowed choices.

Try it yourself: add Cara with four answers: a, a, c, b. She should score 3/4, or 75%, with no blanks. Then turn the marking logic into a function that returns the score and unanswered count, and check it with an all-blank submission.

The lessons on if, elif and else and defining functions help you make those changes without duplicating the marking code.

Project 3: CSV stock checker

The task: read a small table of stock counts and flag every item at or below its reorder threshold. CSV means comma-separated values: the first line names the columns and the following lines hold records.

Save this as stock_checker.py:

import csv
from io import StringIO

csv_text = """item,in_stock,reorder_at
Notebooks,4,5
Pens,12,10
Folders,3,3
"""

low_stock = []
for row in csv.DictReader(StringIO(csv_text)):
    stock = int(row["in_stock"])
    threshold = int(row["reorder_at"])
    if stock <= threshold:
        low_stock.append(row["item"])
        print(f"Reorder {row['item']}: {stock} left (threshold {threshold})")

print(f"Items needing attention: {len(low_stock)}")
assert low_stock == ["Notebooks", "Folders"]

Expected output:

Reorder Notebooks: 4 left (threshold 5)
Reorder Folders: 3 left (threshold 3)
Items needing attention: 2

StringIO lets the CSV reader treat the text in the example like a file. DictReader uses the header to give each value a name, and int converts the stock counts from text into integers.

Folders has exactly three units and a threshold of three. It belongs in the report because the rule is at or below, represented by <=. Changing that comparison to < would silently miss the boundary case. Pens stays out because 12 is greater than its threshold of 10.

Try it yourself: change Pens to a stock count of 9. The report should contain all three items. Next, put the CSV text in your own file and read it with open and encoding="utf-8". Decide how to report a blank or non-numeric stock count; do not silently treat an unknown quantity as zero.

For larger exports, follow the streaming CSV example, which rejects malformed fields and reports discarded records. Use the traceback walkthrough to diagnose a failing conversion.

Continue with working with files and exceptions to handle those inputs deliberately.

Turn an example into your own project

A useful beginner project is finished when you can explain its rules and check its output. Before adding a web interface, complete these steps:

  1. Change the input and predict the new output before running the code.
  2. Put repeated logic into a small function with a clear name.
  3. Check the empty input, an ordinary input and a boundary such as the stock threshold.
  4. Write a short README explaining how to run the script and what its inputs mean.
  5. Record one limitation and the next change you would make.

The testing with assert and pytest lesson develops the checks you started here. For the wider learning order, read Python for machine learning.

Common questions

Which Python project should a complete beginner start with?

Start with the study tracker. It has one list, a short loop and a total you can calculate by hand. If those are still new, work through the Python track first and return after the lessons on lists and dictionaries.

Do I need pandas or NumPy for these projects?

No. Start with ordinary Python so you understand the records, loops and calculations. Once these scripts make sense, try pandas projects for beginners for labelled tables, or NumPy projects for beginners for numerical arrays.

Can I use these Python projects for a portfolio or résumé?

Use the examples as starting points. Publish your own extension with instructions, checks and a clear account of what you changed. A copied script alone gives someone little evidence of your understanding. A small project you can explain is more useful than a list of features you cannot defend.

Where is the source code, and can I put it on GitHub?

The complete source code is in the three code blocks above. You can put your version in your own repository, credit the starting example and add your README and checks. There is no separate project repository you need to clone.

Continue with the Python course

Start the SchoolWhool Python track to learn the ideas these projects use in order: control flow, data structures, functions, files and testing. Open lesson parts and key terms are free to read; a free account adds quizzes and saved progress.

Try the opening modules' free sample to see the practice material. For the Pro practice and project offering, see the plan details and current availability.

References

The examples and teaching data above are original to this article. For the underlying Python behaviour, see the official data structures tutorial, control-flow tutorial and CSV module documentation.

Related course

Learn Python from zero, the way machine learning code uses it: names and objects, types, control flow, data structures, functions, classes, testing and working with an AI assistant.

Open lessons' parts and key terms are free to read, with no account.

What you will be able to do

  • Predict what a piece of Python code does before running it.
  • Read an error message and find the line that caused it.
  • Write functions, classes and tests for real data tasks.
  • Read and check code an AI assistant wrote for you.