pyplayground-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ .eggs/
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+
17
+ # Testing / caches
18
+ .pytest_cache/
19
+ .coverage
20
+ htmlcov/
21
+
22
+ # IDE / OS
23
+ .vscode/
24
+ .idea/
25
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyplayground-cli
3
+ Version: 0.1.0
4
+ Summary: A menu-driven CLI collection of five beginner-friendly Python programs.
5
+ Project-URL: Homepage, https://github.com/yourusername/pyplayground-cli
6
+ Project-URL: Repository, https://github.com/yourusername/pyplayground-cli
7
+ Project-URL: Issues, https://github.com/yourusername/pyplayground-cli/issues
8
+ Author-email: Your Name <you@example.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: beginner,calculator,cli,games,playground
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Education
24
+ Requires-Python: >=3.9
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.0; extra == 'dev'
27
+ Requires-Dist: pytest>=8.0; extra == 'dev'
28
+ Requires-Dist: twine>=5.0; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # pyplayground-cli
32
+
33
+ A clean, menu-driven Python command-line application bundling five beginner-friendly utility and game programs, built with modern Python packaging standards (`pyproject.toml`, `src/` layout, Hatchling).
34
+
35
+ ## Features
36
+
37
+ - Zero external runtime dependencies (pure Python standard library).
38
+ - Interactive menu with graceful handling of invalid inputs and interrupts.
39
+ - Five independent, modular programs:
40
+ 1. **Calculator** — Basic arithmetic (`+`, `-`, `*`, `/`) with zero-division protection.
41
+ 2. **Number Guessing Game** — Guess a secret number between 1 and 100 within 7 attempts.
42
+ 3. **Temperature Converter** — Convert between Celsius and Fahrenheit.
43
+ 4. **Multiplication Table Generator** — Print a multiplication table for any integer up to a chosen bound.
44
+ 5. **Even/Odd Number Checker** — Determine whether an integer is even or odd.
45
+
46
+ ## Requirements
47
+
48
+ - Python 3.9 or higher
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install pyplayground-cli
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ After installation, launch the application from anywhere in your terminal:
59
+
60
+ ```bash
61
+ python-playground
62
+ ```
63
+
64
+ ### Example Terminal Output
65
+
66
+ ```text
67
+ Welcome to Python Playground!
68
+
69
+ Which program would you like to run?
70
+ 1. Calculator
71
+ 2. Number Guessing Game
72
+ 3. Temperature Converter
73
+ 4. Multiplication Table Generator
74
+ 5. Even/Odd Number Checker
75
+ 0. Exit
76
+
77
+ Enter your choice (0-5): 5
78
+
79
+ --- Even/Odd Number Checker ---
80
+ Enter an integer: 42
81
+ 42 is even.
82
+
83
+ Which program would you like to run?
84
+ ...
85
+ ```
86
+
87
+ ## Development Setup
88
+
89
+ Clone the repository and install in editable mode with development dependencies:
90
+
91
+ ```bash
92
+ git clone https://github.com/yourusername/pyplayground-cli.git
93
+ cd pyplayground-cli
94
+ python3 -m venv .venv
95
+ source .venv/bin/activate
96
+ pip install -e ".[dev]"
97
+ ```
98
+
99
+ ## Running Tests
100
+
101
+ ```bash
102
+ pytest
103
+ ```
104
+
105
+ ## Contributing
106
+
107
+ Contributions are welcome! Please open an issue or submit a pull request with clear descriptions and passing tests.
108
+
109
+ ## License
110
+
111
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,81 @@
1
+ # pyplayground-cli
2
+
3
+ A clean, menu-driven Python command-line application bundling five beginner-friendly utility and game programs, built with modern Python packaging standards (`pyproject.toml`, `src/` layout, Hatchling).
4
+
5
+ ## Features
6
+
7
+ - Zero external runtime dependencies (pure Python standard library).
8
+ - Interactive menu with graceful handling of invalid inputs and interrupts.
9
+ - Five independent, modular programs:
10
+ 1. **Calculator** — Basic arithmetic (`+`, `-`, `*`, `/`) with zero-division protection.
11
+ 2. **Number Guessing Game** — Guess a secret number between 1 and 100 within 7 attempts.
12
+ 3. **Temperature Converter** — Convert between Celsius and Fahrenheit.
13
+ 4. **Multiplication Table Generator** — Print a multiplication table for any integer up to a chosen bound.
14
+ 5. **Even/Odd Number Checker** — Determine whether an integer is even or odd.
15
+
16
+ ## Requirements
17
+
18
+ - Python 3.9 or higher
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install pyplayground-cli
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ After installation, launch the application from anywhere in your terminal:
29
+
30
+ ```bash
31
+ python-playground
32
+ ```
33
+
34
+ ### Example Terminal Output
35
+
36
+ ```text
37
+ Welcome to Python Playground!
38
+
39
+ Which program would you like to run?
40
+ 1. Calculator
41
+ 2. Number Guessing Game
42
+ 3. Temperature Converter
43
+ 4. Multiplication Table Generator
44
+ 5. Even/Odd Number Checker
45
+ 0. Exit
46
+
47
+ Enter your choice (0-5): 5
48
+
49
+ --- Even/Odd Number Checker ---
50
+ Enter an integer: 42
51
+ 42 is even.
52
+
53
+ Which program would you like to run?
54
+ ...
55
+ ```
56
+
57
+ ## Development Setup
58
+
59
+ Clone the repository and install in editable mode with development dependencies:
60
+
61
+ ```bash
62
+ git clone https://github.com/yourusername/pyplayground-cli.git
63
+ cd pyplayground-cli
64
+ python3 -m venv .venv
65
+ source .venv/bin/activate
66
+ pip install -e ".[dev]"
67
+ ```
68
+
69
+ ## Running Tests
70
+
71
+ ```bash
72
+ pytest
73
+ ```
74
+
75
+ ## Contributing
76
+
77
+ Contributions are welcome! Please open an issue or submit a pull request with clear descriptions and passing tests.
78
+
79
+ ## License
80
+
81
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.21.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyplayground-cli"
7
+ version = "0.1.0"
8
+ description = "A menu-driven CLI collection of five beginner-friendly Python programs."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ { name = "Your Name", email = "you@example.com" },
14
+ ]
15
+ keywords = ["cli", "playground", "beginner", "calculator", "games"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Education",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Topic :: Education",
29
+ ]
30
+ dependencies = []
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest>=8.0",
35
+ "build>=1.0",
36
+ "twine>=5.0",
37
+ ]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/yourusername/pyplayground-cli"
41
+ Repository = "https://github.com/yourusername/pyplayground-cli"
42
+ Issues = "https://github.com/yourusername/pyplayground-cli/issues"
43
+
44
+ [project.scripts]
45
+ python-playground = "pyplayground_cli.main:main"
46
+
47
+ [tool.hatch.build.targets.wheel]
48
+ packages = ["src/pyplayground_cli"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ """pyplayground-cli: A menu-driven collection of five beginner-friendly Python programs."""
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["__version__"]
@@ -0,0 +1,46 @@
1
+ """Simple interactive calculator module."""
2
+
3
+ from typing import Callable
4
+
5
+
6
+ def calculate(num1: float, operator: str, num2: float) -> float:
7
+ """Perform a basic arithmetic operation on two numbers.
8
+
9
+ Args:
10
+ num1: The first operand.
11
+ operator: One of '+', '-', '*', '/'.
12
+ num2: The second operand.
13
+
14
+ Returns:
15
+ The result of the arithmetic operation.
16
+
17
+ Raises:
18
+ ValueError: If the operator is unsupported.
19
+ ZeroDivisionError: If dividing by zero.
20
+ """
21
+ operations: dict[str, Callable[[float, float], float]] = {
22
+ "+": lambda a, b: a + b,
23
+ "-": lambda a, b: a - b,
24
+ "*": lambda a, b: a * b,
25
+ "/": lambda a, b: a / b,
26
+ }
27
+ if operator not in operations:
28
+ raise ValueError(f"Unsupported operator: {operator!r}. Use +, -, *, or /.")
29
+ if operator == "/" and num2 == 0:
30
+ raise ZeroDivisionError("Cannot divide by zero.")
31
+ return operations[operator](num1, num2)
32
+
33
+
34
+ def run() -> None:
35
+ """Run the interactive calculator program."""
36
+ print("\n--- Calculator ---")
37
+ try:
38
+ num1 = float(input("Enter first number: ").strip())
39
+ operator = input("Enter operator (+, -, *, /): ").strip()
40
+ num2 = float(input("Enter second number: ").strip())
41
+ result = calculate(num1, operator, num2)
42
+ print(f"Result: {num1} {operator} {num2} = {result}")
43
+ except ValueError as exc:
44
+ print(f"Invalid input: {exc}")
45
+ except ZeroDivisionError as exc:
46
+ print(f"Error: {exc}")
@@ -0,0 +1,19 @@
1
+ """Even/Odd number checker module."""
2
+
3
+
4
+ def is_even(number: int) -> bool:
5
+ """Return True if number is even, False if odd."""
6
+ return number % 2 == 0
7
+
8
+
9
+ def run() -> None:
10
+ """Run the interactive even/odd number checker."""
11
+ print("\n--- Even/Odd Number Checker ---")
12
+ try:
13
+ number = int(input("Enter an integer: ").strip())
14
+ except ValueError:
15
+ print("Invalid input: please enter a valid integer.")
16
+ return
17
+
18
+ kind = "even" if is_even(number) else "odd"
19
+ print(f"{number} is {kind}.")
@@ -0,0 +1,52 @@
1
+ """Number guessing game module."""
2
+
3
+ import random
4
+
5
+
6
+ def evaluate_guess(guess: int, target: int) -> str:
7
+ """Compare a guess against the target number.
8
+
9
+ Args:
10
+ guess: The user's guessed integer.
11
+ target: The secret target integer.
12
+
13
+ Returns:
14
+ 'low', 'high', or 'correct'.
15
+ """
16
+ if guess < target:
17
+ return "low"
18
+ if guess > target:
19
+ return "high"
20
+ return "correct"
21
+
22
+
23
+ def run(low: int = 1, high: int = 100, max_attempts: int = 7) -> None:
24
+ """Run the interactive number guessing game.
25
+
26
+ Args:
27
+ low: Lower bound (inclusive).
28
+ high: Upper bound (inclusive).
29
+ max_attempts: Maximum number of guesses allowed.
30
+ """
31
+ target = random.randint(low, high)
32
+ print(f"\n--- Number Guessing Game ({low} to {high}) ---")
33
+ print(f"You have {max_attempts} attempts to guess the secret number.")
34
+
35
+ for attempt in range(1, max_attempts + 1):
36
+ raw = input(f"Attempt {attempt}/{max_attempts} - Enter your guess: ").strip()
37
+ try:
38
+ guess = int(raw)
39
+ except ValueError:
40
+ print("Invalid input: please enter a valid integer.")
41
+ continue
42
+
43
+ outcome = evaluate_guess(guess, target)
44
+ if outcome == "low":
45
+ print("Too low!")
46
+ elif outcome == "high":
47
+ print("Too high!")
48
+ else:
49
+ print(f"Congratulations! You guessed {target} in {attempt} attempt(s).")
50
+ return
51
+
52
+ print(f"Out of attempts! The secret number was {target}.")
@@ -0,0 +1,63 @@
1
+ """Main CLI entry point for pyplayground-cli."""
2
+
3
+ from typing import Callable
4
+
5
+ from pyplayground_cli import (
6
+ calculator,
7
+ even_odd,
8
+ guessing_game,
9
+ multiplication,
10
+ temperature,
11
+ )
12
+
13
+ PROGRAMS: dict[str, tuple[str, Callable[[], None]]] = {
14
+ "1": ("Calculator", calculator.run),
15
+ "2": ("Number Guessing Game", guessing_game.run),
16
+ "3": ("Temperature Converter", temperature.run),
17
+ "4": ("Multiplication Table Generator", multiplication.run),
18
+ "5": ("Even/Odd Number Checker", even_odd.run),
19
+ }
20
+
21
+
22
+ def display_menu() -> None:
23
+ """Print the main menu options."""
24
+ print("\nWhich program would you like to run?")
25
+ for key, (name, _) in PROGRAMS.items():
26
+ print(f" {key}. {name}")
27
+ print(" 0. Exit")
28
+
29
+
30
+ def main() -> int:
31
+ """Run the interactive menu loop.
32
+
33
+ Returns:
34
+ Exit status code (0 for clean exit).
35
+ """
36
+ print("Welcome to Python Playground!")
37
+
38
+ while True:
39
+ display_menu()
40
+ try:
41
+ choice = input("\nEnter your choice (0-5): ").strip()
42
+ except (EOFError, KeyboardInterrupt):
43
+ print("\nGoodbye!")
44
+ return 0
45
+
46
+ if choice == "0":
47
+ print("Goodbye!")
48
+ return 0
49
+
50
+ entry = PROGRAMS.get(choice)
51
+ if entry is None:
52
+ print("Invalid selection. Please choose a number between 0 and 5.")
53
+ continue
54
+
55
+ _, program_fn = entry
56
+ try:
57
+ program_fn()
58
+ except (EOFError, KeyboardInterrupt):
59
+ print("\nReturning to main menu.")
60
+
61
+
62
+ if __name__ == "__main__":
63
+ raise SystemExit(main())
@@ -0,0 +1,35 @@
1
+ """Multiplication table generator module."""
2
+
3
+
4
+ def generate_table(number: int, up_to: int = 10) -> list[str]:
5
+ """Generate formatted multiplication table lines for a given integer.
6
+
7
+ Args:
8
+ number: The base integer for the multiplication table.
9
+ up_to: The upper multiplier bound (inclusive, must be >= 1).
10
+
11
+ Returns:
12
+ A list of formatted strings like '5 x 1 = 5'.
13
+
14
+ Raises:
15
+ ValueError: If up_to is less than 1.
16
+ """
17
+ if up_to < 1:
18
+ raise ValueError("Upper bound must be at least 1.")
19
+ return [f"{number} x {i} = {number * i}" for i in range(1, up_to + 1)]
20
+
21
+
22
+ def run() -> None:
23
+ """Run the interactive multiplication table generator."""
24
+ print("\n--- Multiplication Table Generator ---")
25
+ try:
26
+ number = int(input("Enter an integer: ").strip())
27
+ limit_raw = input("Up to (default 10): ").strip()
28
+ up_to = int(limit_raw) if limit_raw else 10
29
+ lines = generate_table(number, up_to)
30
+ except ValueError as exc:
31
+ print(f"Invalid input: {exc}")
32
+ return
33
+
34
+ for line in lines:
35
+ print(line)
@@ -0,0 +1,36 @@
1
+ """Temperature converter module (Celsius <-> Fahrenheit)."""
2
+
3
+
4
+ def celsius_to_fahrenheit(celsius: float) -> float:
5
+ """Convert Celsius to Fahrenheit."""
6
+ return (celsius * 9.0 / 5.0) + 32.0
7
+
8
+
9
+ def fahrenheit_to_celsius(fahrenheit: float) -> float:
10
+ """Convert Fahrenheit to Celsius."""
11
+ return (fahrenheit - 32.0) * 5.0 / 9.0
12
+
13
+
14
+ def run() -> None:
15
+ """Run the interactive temperature converter."""
16
+ print("\n--- Temperature Converter ---")
17
+ print("1. Celsius to Fahrenheit")
18
+ print("2. Fahrenheit to Celsius")
19
+ choice = input("Choose conversion (1 or 2): ").strip()
20
+
21
+ if choice not in {"1", "2"}:
22
+ print("Invalid choice. Please select 1 or 2.")
23
+ return
24
+
25
+ try:
26
+ value = float(input("Enter temperature value: ").strip())
27
+ except ValueError:
28
+ print("Invalid input: please enter a numeric temperature.")
29
+ return
30
+
31
+ if choice == "1":
32
+ converted = celsius_to_fahrenheit(value)
33
+ print(f"{value:.2f} °C = {converted:.2f} °F")
34
+ else:
35
+ converted = fahrenheit_to_celsius(value)
36
+ print(f"{value:.2f} °F = {converted:.2f} °C")
@@ -0,0 +1,133 @@
1
+ """Automated tests for pyplayground-cli."""
2
+
3
+ import pytest
4
+
5
+ import pyplayground_cli
6
+ from pyplayground_cli import (
7
+ calculator,
8
+ even_odd,
9
+ guessing_game,
10
+ main,
11
+ multiplication,
12
+ temperature,
13
+ )
14
+
15
+
16
+ def test_package_version() -> None:
17
+ assert pyplayground_cli.__version__ == "0.1.0"
18
+
19
+
20
+ # --- Calculator tests ---
21
+
22
+ def test_calculate_operations() -> None:
23
+ assert calculator.calculate(10, "+", 5) == 15
24
+ assert calculator.calculate(10, "-", 5) == 5
25
+ assert calculator.calculate(10, "*", 5) == 50
26
+ assert calculator.calculate(10, "/", 4) == 2.5
27
+
28
+
29
+ def test_calculate_errors() -> None:
30
+ with pytest.raises(ZeroDivisionError):
31
+ calculator.calculate(10, "/", 0)
32
+ with pytest.raises(ValueError):
33
+ calculator.calculate(10, "^", 2)
34
+
35
+
36
+ def test_calculator_run_valid_and_invalid(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
37
+ inputs = iter(["12", "+", "8"])
38
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
39
+ calculator.run()
40
+ assert "20.0" in capsys.readouterr().out
41
+
42
+ inputs = iter(["abc", "+", "8"])
43
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
44
+ calculator.run()
45
+ assert "Invalid input" in capsys.readouterr().out
46
+
47
+
48
+ # --- Number Guessing Game tests ---
49
+
50
+ def test_evaluate_guess() -> None:
51
+ assert guessing_game.evaluate_guess(10, 50) == "low"
52
+ assert guessing_game.evaluate_guess(75, 50) == "high"
53
+ assert guessing_game.evaluate_guess(50, 50) == "correct"
54
+
55
+
56
+ def test_guessing_game_run_win(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
57
+ monkeypatch.setattr(guessing_game.random, "randint", lambda _a, _b: 42)
58
+ inputs = iter(["10", "bad", "50", "42"])
59
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
60
+ guessing_game.run(max_attempts=5)
61
+ out = capsys.readouterr().out
62
+ assert "Too low!" in out
63
+ assert "Invalid input" in out
64
+ assert "Too high!" in out
65
+ assert "Congratulations! You guessed 42" in out
66
+
67
+
68
+ # --- Temperature Converter tests ---
69
+
70
+ def test_temperature_conversions() -> None:
71
+ assert temperature.celsius_to_fahrenheit(0) == 32.0
72
+ assert temperature.celsius_to_fahrenheit(100) == 212.0
73
+ assert temperature.fahrenheit_to_celsius(32) == 0.0
74
+ assert temperature.fahrenheit_to_celsius(212) == 100.0
75
+
76
+
77
+ def test_temperature_run(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
78
+ inputs = iter(["1", "100"])
79
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
80
+ temperature.run()
81
+ assert "100.00 °C = 212.00 °F" in capsys.readouterr().out
82
+
83
+ inputs = iter(["9"])
84
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
85
+ temperature.run()
86
+ assert "Invalid choice" in capsys.readouterr().out
87
+
88
+
89
+ # --- Multiplication Table Generator tests ---
90
+
91
+ def test_generate_table() -> None:
92
+ assert multiplication.generate_table(3, 3) == ["3 x 1 = 3", "3 x 2 = 6", "3 x 3 = 9"]
93
+ with pytest.raises(ValueError):
94
+ multiplication.generate_table(3, 0)
95
+
96
+
97
+ def test_multiplication_run(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
98
+ inputs = iter(["4", "2"])
99
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
100
+ multiplication.run()
101
+ out = capsys.readouterr().out
102
+ assert "4 x 1 = 4" in out
103
+ assert "4 x 2 = 8" in out
104
+
105
+
106
+ # --- Even/Odd Checker tests ---
107
+
108
+ def test_is_even() -> None:
109
+ assert even_odd.is_even(4) is True
110
+ assert even_odd.is_even(7) is False
111
+ assert even_odd.is_even(0) is True
112
+
113
+
114
+ def test_even_odd_run(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
115
+ inputs = iter(["7"])
116
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
117
+ even_odd.run()
118
+ assert "7 is odd." in capsys.readouterr().out
119
+
120
+
121
+ # --- Main Menu / CLI tests ---
122
+
123
+ def test_main_menu_navigation_and_exit(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
124
+ inputs = iter(["99", "5", "8", "0"])
125
+ monkeypatch.setattr("builtins.input", lambda _: next(inputs))
126
+ exit_code = main.main()
127
+ out = capsys.readouterr().out
128
+ assert exit_code == 0
129
+ assert "Welcome to Python Playground!" in out
130
+ assert "Which program would you like to run?" in out
131
+ assert "Invalid selection" in out
132
+ assert "8 is even." in out
133
+ assert "Goodbye!" in out