Using Python as a Calculator

Doing math in python

Source

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!

More by this Author

  • Common Law Court of Record
    4

    An old traditional court of common law, though antiquated can still have modern uses. Is this dinosour still used? If so How? This is a brief look at one very complicated instrument of law revolving around the concept...

  • Create Beats With Hydrogen Drum Machine
    9

    The full view of Hydrogen Good news is that it ships with many distributions like 64studio and Medibuntu. That means the live cd will run it, and you won't have to go through installing a new operating system just to...

  • Become a Freeman-on-the-land
    12

    In my research for common law remedies of which I wrote a hub about, I've come across a movement known as the Freeman-on-the-land. I hadn't heard the term in over a decade. It has been since I knew a fellow who had...


Comments 4 comments

chetanbhasin 4 years ago

And how is that better than perl or PHP?


Portamenteff profile image

Portamenteff 4 years ago from Western Colorado, USA Author

I"m not sure that it is better than PERL or ?PHP but I personally like it better. I'm studying web2py framework right now so having a Python terminal open is handy for me to make sure syntax is good. Some people don't like any of those languages. They only use RubyOnRails for web work.


chetanbhasin 4 years ago

RubyOnRails... hmm...

Well! I believe pearl is good, but as far as user friendly syntax are concerned, I believe PHP is better.


Portamenteff profile image

Portamenteff 4 years ago from Western Colorado, USA Author

PHP certainly is the most available on web hosts. It works really well with databases too.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working