项目作者: MichaelKim0407

项目描述 :
Py-Calculator is a Python-based, easy-to-use calculator.
高级语言: Python
项目地址: git://github.com/MichaelKim0407/PyCalculator.git
创建时间: 2016-06-16T07:36:54Z
项目社区:https://github.com/MichaelKim0407/PyCalculator

开源协议:

下载


PyCalculator v2

Author: Michael Kim mkim0407@gmail.com

Installation

  1. Make sure you have Python2.7 or Python3.4+

  2. Install using pip

    1. pip install mkpycalc

Run

A script named pycalc should be automatically installed by pip.

  1. Run in interactive mode

    1. pycalc
  2. Evaluate single expression

    1. pycalc EXPRESSION

    There is no need to quote the expression.

    However, if the expression contains *, your shell may replace it with file names under current working directory, in which case you do need to quote the expression.

Basic usages

  1. Enter any expression and get the result.

    1. :1 + 2
    2. 3
  2. The result will be stored (in _) for the next expression.

    1. :1 + 2
    2. 3
    3. :+ 6
    4. 9
    5. :2 ** _
    6. 512

    Note: To use +/- as positive/negative signs instead of add/subtract, surround the number with parentheses.

    1. :10
    2. 10
    3. :-5
    4. 5
    5. :(-5)
    6. -5
  3. Store a value to a variable using >>.

    1. :1 + 2
    2. 3
    3. :>> x
    4. 3
    5. :x
    6. 3
    7. :+ 5 >> y
    8. 8
    9. :y
    10. 8
  4. Use values and functions from the math package of Python.

    1. :sin(pi / 6)
    2. 0.5

Basic controls

  1. To exit the program, enter exit.

  2. To reset the calculator, enter reset.

  3. To list all stored values and functions, enter show.

  4. To clear the screen, enter clear.

Advanced usages (for Python programmers)

  1. An assign statement in Python (=, +=, etc.) is the same as >> and will be stored into _.

    1. :x = 1
    2. 1
    3. :x += 3
    4. 4
  2. Any one-line Python code can be executed.

    1. :1 >> x
    2. 1
    3. :print "---{}---".format(x)
    4. ---1---
  3. Define custom functions using one-line code or a lambda expression.

    1. :def cube(x): return x ** 3
    2. <function cube at ......>
    3. :cube(4)
    4. 64
    5. :sq = lambda x: x ** 2
    6. <function <lambda> at ......>
    7. :sq(5)
    8. 25

Import as a library

Simply import mkpycalc in your Python program and do whatever you want!

License

MIT