A feature-rich, colorful command-line calculator with multiple operation modes, scientific functions, and an intuitive user interface.
- Trigonometric:
sin,cos,tan,asin,acos,atan,sinh,cosh,tanh - Mathematical:
sqrt,cbrt,factorial,abs,ceil,floor,round - Logarithmic:
log,log10,log2,exp - Constants:
pi,e
- Basic Mode - Simple numbered operations (addition, subtraction, multiplication, division, exponentiation).
- Expression Mode - Direct mathematical expression input with complex calculations.
- Scientific Mode - Advanced functions and constants with comprehensive help system.
- Colorized terminal output with beautiful ASCII art banners.
- Color-coded results (green for results, red for errors, cyan for prompts).
- Clean input/output formatting for enhanced readability.
- Structured operation menus for easy navigation.
- Calculation history with storage and viewing capabilities.
- Settings management: degree/radian mode toggle, scientific notation toggle.
- Enhanced error handling with descriptive error messages.
- Complex expression evaluation with safety checks.
- Parentheses balancing validation for mathematical expressions.
- Demo mode to showcase calculator capabilities.
- Built-in help system with function descriptions and examples.
- Screen clearing and history management.
- Input validation for numeric values.
- Expression syntax validation.
- Safe evaluation using restricted eval with allowed functions only.
- Comprehensive error handling for division by zero, invalid inputs, and syntax errors.
- Python 3.6 (or) higher.
- Terminal/Command Prompt with ANSI color support (most modern terminals).
-
Download the calculator:
# Clone or download the CalcPro.py file. wget -L https://raw.githubusercontent.com/Nullkernel/CalcPro/main/CalcPro.py # or simply copy the CalcPro.py file to your desired directory.
-
Make it executable (optional, for Unix-based systems):
chmod +x CalcPro.py
python CalcPro.py
or
python3 CalcPro.py
Choose from numbered options:
[1]Addition[2]Subtraction[3]Multiplication[4]Division[5]Exponentiation
# Basic arithmetic Calculator> 3 + 5 * 2 # Scientific functions Calculator> sqrt(16) + 2^3 # Trigonometric (respects angle mode) Calculator> sin(90) + cos(0) # Logarithmic Calculator> log10(100) + log(e) # Complex expressions Calculator> (2 + 3) * sqrt(25) / factorial(3)
| Command | Description |
|---|---|
1-5 |
Basic arithmetic operations |
6 |
Enter Basic Mode |
7 |
Enter Expression Mode |
8 |
Enter Scientific Mode |
h |
View calculation history |
c |
Clear calculation history |
cl |
Clear screen |
? |
Show help and available functions |
m |
Toggle degree/radian mode |
s |
Toggle scientific notation |
demo |
Run demonstration mode |
x |
Exit calculator |
# Trigonometric functions: sin(angle), cos(angle), tan(angle), asin(x), acos(x), atan(x), sinh(x), cosh(x), tanh(x) # Mathematical functions: sqrt(x), cbrt(x), factorial(n), abs(x), ceil(x), floor(x), round(x) # Logarithmic functions: log(x), log10(x), log2(x), exp(x) # Constants: pi, e # Power operations: pow(x,y), x^y, x**y
- Radians (default): For mathematical calculations
- Degrees: For practical applications
- Toggle with
mcommand
- OFF (default): Standard decimal notation
- ON: Scientific notation (e.g., 1.234567e+02)
- Toggle with
scommand
Calculator> 1 # Enter First Number: 15 # Enter Second Number: 25 # Result: 15.0 + 25.0 = 40 Calculator> 2 + 3 * 4 # Result: 14
Calculator> sqrt(144) # Result: 12 Calculator> sin(90) # (in degree mode) # Result: 1 Calculator> log10(1000) # Result: 3 Calculator> factorial(5) # Result: 120
Calculator> (sqrt(16) + 2^3) / factorial(3) # Result: 2 Calculator> pi * 2 # Result: 6.283185307179586
The calculator provides comprehensive error handling for:
- Invalid numeric input: Clear error messages for non-numeric values.
- Division by zero: Prevents mathematical errors.
- Syntax errors: Validates mathematical expression syntax.
- Unmatched parentheses: Ensures proper expression structure.
- Unknown functions: Helpful suggestions for valid function names.
- Factorial of negative numbers: Mathematical domain validation.
- Colorful ASCII art banner on startup
- Color-coded output:
- Green: Results and success messages.
- Red: Error messages.
- Blue: Section headers.
- Yellow: Input prompts and warnings.
- Cyan: Options and commands.
- Start the calculator:
python CalcPro.py - Try a simple calculation: Enter
2 + 3 - Explore scientific functions: Enter
sqrt(25) - Check history: Enter
h - Get help: Enter
? - Try demo mode: Enter
demo
This calculator is designed to be extensible. You can easily add new functions by:
- Adding the function to the
allowed_namesdictionary inevaluate_expression(). - Adding documentation to the
suggestionsdictionary. - Implementing any custom mathematical functions as needed.
This project is open source and available under standard GNU General Public License v3.0 licensing terms.
If you encounter any issues:
- Check that you're using Python 3.6 (or) higher.
- Ensure your terminal supports ANSI color codes.
- Verify that mathematical expressions follow standard notation.
- Use the
?command for function help - Try the
democommand to see example usage
Happy Calculating!