Enhance README with usage and operations

This commit is contained in:
MoCipher 2026-05-12 16:57:51 +02:00
parent 0b1f5864f7
commit 3aec070640

View file

@ -1,21 +1,48 @@
# Scientific Calculator # 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 ## What it does
- Basic arithmetic operations
- Trigonometric functions - Runs a **REPL-style loop**: choose an operation, enter operands, see `Result: …`, repeat until you exit.
- Logarithms and exponentials - 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 ## Usage
1. Run the calculator:
``` From the project directory:
```bash
python calculator.py python calculator.py
``` ```
## Files Follow the on-screen prompts. For logarithms, leave the base blank to use the natural logarithm (base **e**).
- `calculator.py` — Main calculator script
## Project layout
- **`calculator.py`** — Menu-driven `main()` plus the operation functions (`add`, `subtract`, `multiply`, `divide`, `sine`, `cosine`, `tangent`, `logarithm`, `exponent`).
## Disclaimer ## Disclaimer
For learning purposes. For learning purposes.