This is a simple calculator program that performs single operations on two numbers. It allows the user to input two integer or float values, along with an operator to perform the calculation. The calculator supports various operations, and you can even add your own custom operators. The program also offers the option to activate or deactivate colored output.
- This idea is inspired by: [@MakiWolf] (https://github.com/MakiWolf)
- project: https://github.com/MakiWolf/easysimplifiedcalculator1
- Run the main.py script.
- Follow the instructions displayed on the screen.
- Enter the first number.
- Enter the desired operator from the available options. For example, to perform addition, enter "+". You can use the following operators: addition (+), subtraction (-), division (/), multiplication (*), modulus (%), or random number generation (#).
- Enter the second number.
- The program will calculate the result and display it.
- You can choose to start another calculation by entering the restart keyword ("1"), or stop the program by entering any other input.
To add your own custom operators, follow these steps:
-
Open the operations.py file.
-
Define your operator as a lambda function that takes two arguments and performs the desired calculation. For example, to define a custom operator "**" for exponentiation, you can use the following code:
exp = lambda a, b: a ** b
-
Add your operator to the OPERATIONS dictionary using the desired math symbol as the key and the lambda function as the value. For example, to add the "**" operator, modify the OPERATIONS dictionary as follows:
OPERATIONS = { "+": add, "-": sub, "/": div, "*": mul, "%": mud, "#": rnd, "**": exp }
-
Save the operations.py file.
You can now use your custom operator in the calculator by entering the corresponding math symbol.
By default, the calculator program displays colored output using the colored
module, which internally uses colorama
. However, you can choose to activate or deactivate colored output by modifying the program.
To set the flag for color activation or deactivation, follow these steps:
-
Open the
colored.py
file. -
Locate the
MetaColor
class definition. -
Inside the
MetaColor
class, find theuse_color
flag and set it accordingly:- Set
use_color = True
to activate colored output. - Set
use_color = False
to deactivate colored output.
Here's an example of how the
MetaColor
class should look with theuse_color
flag set:class MetaColor(type): use_color = True
- Set
-
Save the colored.py file.