RSS Feed

Using Python as the most powerful calculator


Once I was looking for “expression calculator”. The expression calculator is different from normal calculator like calc.exe, which cannot use variable freely as algebra. But the expression calculator, we can predefine a variable with a value, then evaluate the variables in algebraic expression. It is very useful. My favourite expression calculator is SpeedCrunch.

Then, recently, I want to test a math function in SpeedCrunch, but this is impossible, since expression calculator can only define the variable, but not define a function. I remembered the title of Python Tutorial, “Using Python as a Calculator“. Yes, expression calculator, with ability to define function, then Python will be the one.

So, I tried Python, writing the function in the interactive console, easy as it is. Not only that, one can do the fractions and also calculating the date time using Python. So, Python is now my #1 expression calculator. The only drawback I found is that Python does not have the mathematic constants as SpeedCrunch. That means, one needs to find the constants, and also the the unit conversion by our own.

Besides that, to use math functions such as logarithm and trigonometry functions, one must import the math module.

from math import *
from fractions import Fraction #to use the fraction
from datetime import *
Advertisements

About Allen Choong

A cognitive science student, a programmer, a philosopher, a Catholic.

2 responses »

  1. Python is my favourite calculator too. A very useful feature of the interactive shell is that it saves the value of the last expression in the special variable “_” (underscore). Ex.: 2 + 3 will print 5. Then you can write _ * 3, which is 15, etc.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: