- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming»
- Programming Languages
Using Python as a Calculator
Doing math in python
A very Easy Language, yet can do it all.
Sometimes I'm building a web page, and I need to calculate some quick math. If I'm in a command line text editor, then I usually just open a new tab and type:
python
It's an easy parser to install, has very few dependencies, can run as a stand alone parser, or embed in web pages. It works on Linux (all variants,) Windows, Mac OSX, and PowerPC, Unix, FreeBSD, and just about any OS or machine I've ever tried. It's been used by everyone from command line scripting, to Video Games, Photo editors, and even NASA in it's shuttle control rooms. I use it for doing simple math.
In the photo here you can see how it is done. You can simply type 2+3 and it will output 5. Or you can if you want to write a program with math in it, type:
MyVar=2
MyNextVar=3
MySolutionVar=MyVar+MyNextVar
Print MySolutionVar
Variables are a word, or short term that is assigned a value. That value can change or be fixed. Creating variables in Python is so easy that I take it for granted when using other languages like JavaScript, PHP, or Java. As a novice/semi-professional web designer I find it quite a tool. Name a file with a .py extension on the end of it, and wrap it in HTML and body tags, and you've got a web page that has very powerful programming in it.
Get it? It can take a literal math problem, or a list of variables. Variable can be strings, (literal characters) or numbers and their actual values they represent. In the bottom of this hub, I'll put some links to help you all get started. Happy Hunting!
The Python Home Page
- Python Programming Language – Official Website
Home page for Python, an interpreted, interactive, object-oriented, extensible programming language. It provides an extraordinary combination of clarity and versatility, and is free and comprehensively ported.
The Python Wiki
- BeginnersGuide - PythonInfo Wiki
A wiki with much info to get you started. I refer to it whenever I get started on some new code.