Sh4dow’s Polish Calculator (SPC) 1.0

SPC

Full Official Stable Code

There may be several versions of the program, however, I recommend that you use the most updated stable version, which you will find by clicking here . This link will redirect you to my github.

Overview

This program shows how you can calculate expressions with normal and inverted Polish notation using Python. This script is intended to function like a normal calculator, using the operators ‘+’, ‘-‘, ‘*’ and ‘/’.

I will assume that you have at least a little knowledge of normal and inverted Polish notation and also on programming, so I will not put too much emphasis on the concepts.

Version

Version: 1.0

License

This project is licensed under a GNU General Public License v3.0.

If you want to know about this license, click here

What is the Polish Notation

POLISH

Polish notation is a form of notation for logic, arithmetic, algebra, and computation. In the technological field, it has seen wide application with Lisp’s S-expressions and is the operating principle of certain calculators, notably those from Hewlett-Packard.

REVERSE

Reverse Polish notation is used to reduce computer memory access and to use stacks to evaluate expressions.

What is Python?

PYTHON

Python is an interpreted programming language whose philosophy emphasizes the readability of its code. It is a multi-paradigm programming language, since it partially supports object-orientation, imperative programming and functional programming.

Using SPC

LOGO

To use the program, you need to have at least Python 3.7, because it was in the version in which it was developed so in older versions it is not known if it would give bugs.

To use the calculator, you only have to download the repository and then use the Python interpreter in the form:

python3 spc.py

This will display how the program is used. You can also use the -h or –help parameter to view the help information.

There are 2 essential parameters: -p or –polish and -i or –inverted, which stand for polish and inverted polish respectively. These work with their respective operation. Some examples would be:

python3 spc.py -p "* 5 2"
python3 spc.py -p "+ 4 / 10 2"
python3 spc.py -p "/ - 50 25 5"
python3 spc.py -i "5 2 *"
python3 spc.py -i "10 2 / 4 +"
python3 spc.py -i "50 25 - 5 /"

Do you want to know more? READ THIS

PYTHON

What the program uses is a method that works for both types of operations, this is done thanks to the parameters.

For the process, a predefined Python list was used as if it were a stack, along with 2 helper variables called temp_1 and temp_2, where they were used to do the corresponding operations. In addition, the variable number, which is a string, was used to store the different numbers of the operation.

First, it is verified what type of operation is going to be carried out, be it a Polish or a reverse Polish. Then, it is verified if the entered operation is a correct operation, because you cannot use the -p parameter and put a reverse Polish operation. In addition, to be more comfortable, the process works with the same format, so if the operation is not inverted, the string will be inverted and thus it will work similar to the reverse one and the calculation will be almost the same for both processes.

The calculation begins with a loop, which goes through the expression and takes the numbers, as integers, to later save them on the “stack” when it finds a space character. If an operator is found, the operation will be done with the last 2 numbers registered in the “stack”.

When the process is finished, only one number will remain on the “stack” which will be the result and will be printed on the screen.

That is all for now. Eat Vegetables and Have a nice day :D