commit 9f6a401f9b6065a255c005b5102def10599e62b3 Author: Jens Tirsvad Nielsen Date: Sat Oct 3 12:10:47 2026 +0800 Add Band Name Generator project with CLI, tests, and documentation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6287d40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# Byte-compiled / cache +__pycache__/ +*.py[cod] +*$py.class + +# Virtual environments +.venv/ +venv/ +env/ +ENV/ + +# Environment files +.env + +# Packaging / build +build/ +dist/ +*.egg-info/ +.eggs/ + +# Test / coverage +.pytest_cache/ +.coverage +.coverage.* +htmlcov/ +.tox/ +.mypy_cache/ +.ruff_cache/ + +# IDEs / OS +.idea/ +.vscode/ +.DS_Store +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b96193 --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +# πŸš€ Band Name Generator + +A beginner-friendly Python program that suggests a band name using the user's hometown and pet's name. + +## πŸ“š Table of Contents + +- [Overview](#-overview) +- [Requirements](#-requirements) +- [Setup](#-setup) +- [Run](#-run) +- [Tests](#-tests) +- [License](#-license) +- [Links](#-links) + +## 🧭 Overview + +This is the Day 1 project from Udemy's [100 Days of Codeβ„’: The Complete Python Pro Bootcamp](https://www.udemy.com/course/100-days-of-code/). The program asks for the city you grew up in and the name of a pet, then combines them into your band name. + +```text +Welcome to the Band Name Generator. +What's the name of the city you grew up in? +Paris +What's the name of a pet? +Rex +Your band name could be: Paris Rex +``` + +## πŸ“‹ Requirements + +- Python 3.13 or newer +- No runtime dependencies (the tests use Python's built-in `unittest`) + +## πŸ› οΈ Setup + +Create a local virtual environment named `.venv` in the project root and activate it. + +Windows (PowerShell): + +```powershell +python -m venv .venv +.venv\Scripts\Activate.ps1 +``` + +Windows (Command Prompt): + +```bat +python -m venv .venv +.venv\Scripts\activate.bat +``` + +macOS / Linux: + +```bash +python3 -m venv .venv +source .venv/bin/activate +``` + +Then install the project in editable mode: + +```bash +python -m pip install -e . +``` + +Run `deactivate` to leave the virtual environment. The `.venv` folder is ignored by Git. + +## ▢️ Run + +With `.venv` active: + +```bash +python -m band_name_generator +``` + +Or use the installed command: + +```bash +band-name-generator +``` + +## πŸ§ͺ Tests + +With `.venv` active: + +```bash +python -m unittest discover -s tests +``` + +## πŸ“„ License + +No license has been chosen yet. Add a `LICENSE` file and name it here once one is picked. + +## πŸ”— Links + +- [Repository](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code) +- [Documentation](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code#readme) +- [Issue tracker](https://git.tirsystem.com/Tirsvad-Udemy-100_days_of_code/issues) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5d987a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["setuptools>=68"] +build-backend = "setuptools.build_meta" + +[project] +name = "band-name-generator" +version = "0.1.0" +description = "Day 1 of 100 Days of Code: suggest a band name from a hometown and a pet's name." +readme = "README.md" +requires-python = ">=3.13" +dependencies = [] + +[project.scripts] +band-name-generator = "band_name_generator.cli:main" + +[tool.setuptools.packages.find] +where = ["src"] diff --git a/src/band_name_generator/__init__.py b/src/band_name_generator/__init__.py new file mode 100644 index 0000000..d89bb13 --- /dev/null +++ b/src/band_name_generator/__init__.py @@ -0,0 +1 @@ +"""Band Name Generator: combine a hometown and a pet's name into a band name.""" diff --git a/src/band_name_generator/__main__.py b/src/band_name_generator/__main__.py new file mode 100644 index 0000000..0ae05b2 --- /dev/null +++ b/src/band_name_generator/__main__.py @@ -0,0 +1,3 @@ +from band_name_generator.cli import main + +main() diff --git a/src/band_name_generator/cli.py b/src/band_name_generator/cli.py new file mode 100644 index 0000000..0b209aa --- /dev/null +++ b/src/band_name_generator/cli.py @@ -0,0 +1,19 @@ +"""Command-line interface for the Band Name Generator.""" + +from band_name_generator.generator import generate_band_name + + +def main() -> None: + print("Welcome to the Band Name Generator.") + city = input("What's the name of the city you grew up in?\n") + pet = input("What's the name of a pet?\n") + try: + band_name = generate_band_name(city, pet) + except ValueError as error: + print(error) + raise SystemExit(1) + print(f"Your band name could be: {band_name}") + + +if __name__ == "__main__": + main() diff --git a/src/band_name_generator/generator.py b/src/band_name_generator/generator.py new file mode 100644 index 0000000..2bfdffc --- /dev/null +++ b/src/band_name_generator/generator.py @@ -0,0 +1,13 @@ +"""Core logic for building a band name.""" + + +def generate_band_name(city: str, pet: str) -> str: + """Combine a city and a pet's name into a band name. + + Raises ValueError if either value is empty or only whitespace. + """ + city = city.strip() + pet = pet.strip() + if not city or not pet: + raise ValueError("Both the city and the pet's name are required.") + return f"{city} {pet}" diff --git a/tests/test_generator.py b/tests/test_generator.py new file mode 100644 index 0000000..3f6e717 --- /dev/null +++ b/tests/test_generator.py @@ -0,0 +1,23 @@ +import unittest + +from band_name_generator.generator import generate_band_name + + +class GenerateBandNameTests(unittest.TestCase): + def test_combines_city_and_pet(self): + self.assertEqual(generate_band_name("Paris", "Rex"), "Paris Rex") + + def test_strips_whitespace(self): + self.assertEqual(generate_band_name(" Paris ", " Rex\n"), "Paris Rex") + + def test_empty_city_raises(self): + with self.assertRaises(ValueError): + generate_band_name("", "Rex") + + def test_blank_pet_raises(self): + with self.assertRaises(ValueError): + generate_band_name("Paris", " ") + + +if __name__ == "__main__": + unittest.main()