Reverse Polish Notation calculator.
Project description
RPN
===
Reverse Polish Notation calculator for Python.
Binary Operators
----------------
* ``+``: addition
* ``-``: subtraction
* ``*``: multiplication
* ``/``: true division
* ``%``: modulo
* ``//``: floor division
* ``**``: exponentation
Unary Operators
---------------
* ``abs``: absolute value
* ``sqrt``: square root
* ``ceil``: rounding up
* ``floor``: rounding down
Examples
--------
::
import decimal
import rpn
result = rpn.solve_rpn('3.4 -3 abs + 100 sqrt -')
print(result) # 3.6
try:
rpn.solve_rpn('3 3 3 +')
rpn.solve_rpn('3 +')
rpn.solve_rpn('abs')
rpn.solve_rpn('3 a +')
except RPNError:
...
try:
rpn.solve_rpn('0 5 /')
except decimal.DivisionByZero:
...
try:
rpn.solve_rpn('-5 sqrt')
except decimal.InvalidOperation:
...
try:
rpn.solve_rpn('9999999999999 9999999999999 **')
except decimal.Overflow:
...
CLI Usage
---------
::
$ rpn "1 2 + 8 -"
$ 5
===
Reverse Polish Notation calculator for Python.
Binary Operators
----------------
* ``+``: addition
* ``-``: subtraction
* ``*``: multiplication
* ``/``: true division
* ``%``: modulo
* ``//``: floor division
* ``**``: exponentation
Unary Operators
---------------
* ``abs``: absolute value
* ``sqrt``: square root
* ``ceil``: rounding up
* ``floor``: rounding down
Examples
--------
::
import decimal
import rpn
result = rpn.solve_rpn('3.4 -3 abs + 100 sqrt -')
print(result) # 3.6
try:
rpn.solve_rpn('3 3 3 +')
rpn.solve_rpn('3 +')
rpn.solve_rpn('abs')
rpn.solve_rpn('3 a +')
except RPNError:
...
try:
rpn.solve_rpn('0 5 /')
except decimal.DivisionByZero:
...
try:
rpn.solve_rpn('-5 sqrt')
except decimal.InvalidOperation:
...
try:
rpn.solve_rpn('9999999999999 9999999999999 **')
except decimal.Overflow:
...
CLI Usage
---------
::
$ rpn "1 2 + 8 -"
$ 5
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
rpn-1.0.tar.gz
(2.6 kB
view details)
File details
Details for the file rpn-1.0.tar.gz.
File metadata
- Download URL: rpn-1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1923b2c401cfe6b77237d7993f21c2f7936eb898594be0d1a7e569ab74c0d98
|
|
| MD5 |
62ce54c50ba86816eba16f17ef2f1bac
|
|
| BLAKE2b-256 |
36ebd28fa89939368eab8de08474f7cd96a14febd6f29ad8cac7cd21c05cb04e
|