From 3aec07064021784ac55fb32d264750a27c251559 Mon Sep 17 00:00:00 2001 From: MoCipher Date: Tue, 12 May 2026 16:57:51 +0200 Subject: [PATCH] Enhance README with usage and operations --- README.md | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e981614..170232e 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,48 @@ - # Scientific Calculator -A simple scientific calculator built in Python. +An interactive **command-line** scientific calculator written in Python. It presents a numbered menu, reads your inputs, and prints results for each operation. The core math lives in small functions in `calculator.py`, so you can also import them from another script if you want to reuse the same behavior. -## Features -- Basic arithmetic operations -- Trigonometric functions -- Logarithms and exponentials +## What it does + +- Runs a **REPL-style loop**: choose an operation, enter operands, see `Result: …`, repeat until you exit. +- Uses only the **Python standard library** (`math`); no extra packages to install. +- **Validates** some edge cases: division by zero and logarithms of non-positive numbers raise clear errors instead of failing silently. + +## Operations + +| Choice | Operation | Inputs | Notes | +|--------|-----------|--------|--------| +| 1 | Add | `x`, `y` | | +| 2 | Subtract | `x`, `y` | | +| 3 | Multiply | `x`, `y` | | +| 4 | Divide | `x`, `y` | Error if `y` is zero | +| 5 | Sine | `x` | `x` is in **radians** | +| 6 | Cosine | `x` | **radians** | +| 7 | Tangent | `x` | **radians** | +| 8 | Logarithm | `x`, optional base | `x` must be **> 0**; base defaults to **e** if you press Enter | +| 9 | Exponent | `x`, `y` | `x` to the power `y` (`math.pow`) | +| 0 | Exit | — | Ends the program | + +Invalid menu choices print `Invalid choice.` Other problems (bad numeric input, domain errors) print `Error: …` with the exception message. + +## Requirements + +- Python 3 (any recent 3.x is fine) ## Usage -1. Run the calculator: - ``` - python calculator.py - ``` -## Files -- `calculator.py` — Main calculator script +From the project directory: + +```bash +python calculator.py +``` + +Follow the on-screen prompts. For logarithms, leave the base blank to use the natural logarithm (base **e**). + +## Project layout + +- **`calculator.py`** — Menu-driven `main()` plus the operation functions (`add`, `subtract`, `multiply`, `divide`, `sine`, `cosine`, `tangent`, `logarithm`, `exponent`). ## Disclaimer + For learning purposes.