ScientificCalculator/README.md
2026-05-12 16:57:51 +02:00

48 lines
1.8 KiB
Markdown

# Scientific Calculator
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.
## 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
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.