Saturday 18 July 2015

My first Python Application - Add, Multiply ,Subtract, Divide


Whenever I learn a new programming language, a calculator is the first application I build. It is because, calculator is always useful and you can build it b some basic programming knowledge.
To work with data , lets get used to the language.

Requirements  : basic knowledge of Python.

To get acquainted with python before starting this application please click here. 

For programmers, this application may be a cake walk. If you are a beginner then I will encourage you to use this as application as a guideline to build your own application. 

In this application, we will perform basic Mathematical Operations i.e. add,subtract,multiply and divide. We will write four functions for these operations. the functions are shown below.

Note : I am executing this application in Spyder that comes with Anaconda. You may choose any IDE to write this Application.

Add function will look like this :



Similarly, let us do it for other three operations.



Try to call these operations from a main function a shown below :


It is not necessary to define a main function in Python. But try to define it as the code becomes more readable and it is very easy to spot a logical error if there is any.

When I run this application the interpreter starts from the top and looks out for an call. For now, it is main() as all other are "def" i.e. all others are function signatures. So, your program will start from a line that is not a function signature.

In my next blog, I will try to come up with a more of a data science related tutorial.

No comments:

Post a Comment