Skip to main content

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

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rpn, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size rpn-1.0.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page