Calculator Project
Project description
Calculator
This is a simple calculator program written in Python that performs basic arithmetic operations such as addition, subtraction, multiplication, division, and taking the root of a number. The calculator uses the Decimal module to ensure precision in calculations.
Installation
Use the following command to install
pip install calculator_project_231023
Usage
To use the calculator, follow these steps:
- Import the pacakge.
- Run the main interface function run_interface().
- You will be prompted to enter the first number (integer or float).
- After entering the first number, you will be prompted to choose an arithmetic operation (+, -, *, /, **) for the calculation.
- Enter the second number (integer or float).
- The program will perform the selected arithmetic operation on the first and second numbers and display the result.
- You will then be prompted to choose the next action:
- Enter 'C' to continue using the current result as the first number for the next operation.
- Enter 'R' to reset the calculator result to 0 and start a new calculation.
- Enter 'Q' to quit the program.
- Repeat the calculation loop as desired.
Example
import calculator_project_231023
run_interface()
Your interaction will be something like this:
Welcome to the calculator
Use it to add, subtract, multiply, divide, or take a root
Enter the first element (integer or float): 5
Enter arithmetic operation (options: +, -, *, /, **): *
Enter the second element (integer or float): 2
Result: 10
C to continue with the result, R to reset result to 0, Q to quit: c
Enter arithmetic operation (options: +, -, *, /, **): +
Enter the second element (integer or float): 3
Result: 13
C to continue with the result, R to reset result to 0, Q to quit: c
Enter arithmetic operation (options: +, -, *, /, **): **
Enter the second element (integer or float): 0.5
Result: 3.605551275
C to continue with the result, R to reset result to 0, Q to quit: R
Calculator reset to 0
Enter the first element (integer or float): 10
Enter arithmetic operation (options: +, -, *, /, **): /
Enter the second element (integer or float): 3
Result: 3.3333333333
C to continue with the result, R to reset result to 0, Q to quit: Q
Thank you for using the calculator
Notes
- The calculator uses the Decimal data type for more precise calculations. The precision of the calculator can be adjusted by modifying the PRECISION constant in the code. It is 10 decimal places by default.
- The calculator stores the most recent result and applies additional operations to that result until explicitly instructed to clear the result.
- The calculator supports the following arithmetic operations: addition (+), subtraction (-), multiplication (*), division (/), and taking the root (**).
- To take the root of a specific power you only need to inter the power. For instace to take a 3rd degree root of 8 you enter 3 after selecting the ** operation. Your input sequence looks like this 8 ** 3, but the actual calculation happens in the following format: 8**(1/3).
- The calcualtor does not allow to take a root of a negative number. But it allows to enter a negavite power, for example your input sequence could look like this 8 ** -3, but the actual calculation happens in the following format: 8**(1/-3).
- The calculator prompts the user for valid number inputs and handles any invalid inputs with appropriate error messages.
- The calculator allows the user to continue using the current result for subsequent operations, reset the calculator result to 0, or quit the program.
- The program can be terminated at the end of one calculation cycle by entering 'Q' as the next action, or at any time by 'ctrl+Q'.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for calculator_project_231023-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6255f1aa00ec1acb5a38cca4eba3f67b9c9eade0fcedf83c7a90c5819cb9a98e |
|
MD5 | 578111db8acfe9fb71479c29775be3c3 |
|
BLAKE2b-256 | b611f15740a32d2ec94dede6f2077e339fb3ebf506ca7f96fb5bdc6e61830eef |
Close
Hashes for calculator_project_231023-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1854cb3c293fd6fee9ee3c1635d0ed222579b55f3652b128b09dca59c1b75298 |
|
MD5 | e248f1e7f8c42a657466c150647ca29b |
|
BLAKE2b-256 | fc3fe98620403c38bea11e6d3d18db5b53694f5cf5f6028c97394066e47ec0d3 |