ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

Using Python as a Calculator

Updated on March 8, 2012

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:


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:




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!


    0 of 8192 characters used
    Post Comment

    • Portamenteff profile image

      Portamenteff 6 years ago from Western Colorado, USA

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

    • profile image

      chetanbhasin 6 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 6 years ago from Western Colorado, USA

      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.

    • profile image

      chetanbhasin 6 years ago

      And how is that better than perl or PHP?