Skip to content

Latest commit

 

History

History
168 lines (120 loc) · 3.92 KB

README.md

File metadata and controls

168 lines (120 loc) · 3.92 KB

Python Debugging Lab

A small portfolio project showing practical Python debugging, bug explanation, edge-case handling, and test-driven fixes.

This repo contains intentionally broken Python functions, corrected versions, and pytest tests that show the before/after debugging process.

Purpose

The goal of this project is to demonstrate beginner-to-intermediate Python debugging skills in a clear, practical way.

It shows how to:

  • Identify common Python bugs
  • Explain why the code fails
  • Write cleaner fixed versions
  • Add edge-case handling
  • Use tests to verify the fix

This type of work matches the kind of help many coding clients need: understanding why code is broken, fixing the issue, and learning how to avoid the same mistake again.

Technologies Used

  • Python 3
  • pytest
  • Standard Python library only

Project Structure

python-debugging-lab/
├── debugging_lab/
│   ├── __init__.py
│   ├── broken_examples.py
│   └── fixed_examples.py
├── examples/
│   └── run_examples.py
├── tests/
│   ├── test_broken_examples_expected_failures.py
│   └── test_fixed_examples.py
├── .gitignore
├── requirements.txt
└── README.md

Features

This project includes seven debugging examples:

  1. Palindrome checker bug
  2. Full name formatter bug
  3. Positive number filter bug
  4. Safe division bug
  5. Customer record cleanup bug
  6. Duplicate finder bug
  7. Date formatter bug

Each example includes:

  • A broken version
  • A fixed version
  • Tests for the fixed version
  • Expected-failure tests for the broken version
  • Clear comments explaining the issue

How to Run

Clone the repo:

git clone https://github.com/YOUR-USERNAME/python-debugging-lab.git
cd python-debugging-lab

Create and activate a virtual environment:

python -m venv .venv

On Windows:

.venv\Scripts\activate

On macOS/Linux:

source .venv/bin/activate

Install dependencies:

pip install -r requirements.txt

Run the tests:

pytest

Run the example script:

python examples/run_examples.py

Example

Broken version

def is_palindrome(text):
    return text == text[::-1]

Problem: this only works for exact character matches. It fails when the input has uppercase letters, spaces, or punctuation.

Example failure:

is_palindrome("Racecar")
# False, but expected True

Fixed version

def is_palindrome(text: str) -> bool:
    normalized = "".join(char.lower() for char in text if char.isalnum())
    return normalized == normalized[::-1]

Example result:

is_palindrome("A man, a plan, a canal: Panama")
# True

Debugging Examples Summary

Example Bug Fix
Palindrome checker Compared raw text only Normalize case and remove punctuation
Full name formatter Left messy spaces and failed on missing last name Strip input and safely join name parts
Positive number filter Included zero and crashed on non-numeric values Keep only real numbers greater than zero
Safe division Crashed on division by zero Return None when divisor is zero
Customer cleanup Assumed every dictionary had every key Use safe defaults and type checks
Duplicate finder Returned repeated duplicate values Return each duplicate once
Date formatter Accepted only one exact date format Support multiple common formats

What This Demonstrates

This project demonstrates practical coding-help skills:

  • Reading and understanding existing code
  • Finding logic bugs
  • Handling edge cases
  • Improving function reliability
  • Writing simple tests
  • Explaining fixes clearly

Notes

The broken examples are intentionally incorrect. The tests in test_broken_examples_expected_failures.py are marked with xfail, which means pytest expects them to fail. This makes the debugging process visible without breaking the full test suite.