项目作者: archman

项目描述 :
RPN calculator for Python
高级语言: Python
项目地址: git://github.com/archman/pyrpn.git
创建时间: 2016-02-03T06:36:55Z
项目社区:https://github.com/archman/pyrpn

开源协议:MIT License

下载


pyrpn

travisci
python2.7
python3.5
python3.6

Reverse Polish Notation calculator by python.

  • Builtin operations:
    • +, -, *, /, sin, cos, tan, sqrt, pop, swap, sto
  • Constants:
    • pi
  • Other operations could be added (development)
  • Shell script command: pyrpn

Examples

  • Use pyrpn in Python (2.7, 3.5, 3.6) terminal:
  1. >>> from pyrpn import Rpn
  2. >>> Rpn('1 2 +').solve()
  3. 3.0
  4. >>> Rpn('30 180 / pi * cos').solve()
  5. 0.8660254037844214
  6. >>> Rpn('0.2 10.24 pi * 180 / * 10.24 pi * 180 / sin /').solve()
  7. 0.20106869612225164
  8. >>> Rpn.solve_rpn('1 2 +')
  9. 3.0
  10. >>> from pyrpn import solve_rpn
  11. >>> solve_rpn('1 2 +')
  12. 3.0
  • Use pyrpn in Linux terminal:
    ```Shell
    $ pyrpn
    Welcome to RPN calculator, powered by Python.

pyrpn 1.0.4 — Python package for reverse polish notation expression.
help —> Show usage message.
exit, quit —> Exit.

pyrpn shell > 2.0 sqrt
pyrpn shell > 1.4142135623730951
pyrpn shell > -1 sin sqrt
Input of sqrt must be a positive number.
Invalid RPN, fix it and try again.:)
pyrpn shell > 1 2 3 pop +
pyrpn shell > 3.0000000000000000
pyrpn shell > 1 2 + sto three pop three 2 *
pyrpn shell > 6.0000000000000000
```