Programs and Algorithms in Python
Algorithm
- An algorithm is description to solve a problem.
- It is a step by step process to solve any kind of problem.
- Their can be different algorithms to solve same problem. It varies from person to person
- Algorithm is written and analyzed in different programming language.
Example
If you want an do arithmetic addition of two numbers and save it to a location, then algorithm will be
Step 1: Take one number and save it to a variable named 'a'.
Step 2: Take another number and save it to a variable named 'b'.
Step 3: Simply perform a+b and save it to variable named 'x'.
So equation for this step will be x = a+b;
Step 4: Display value of x.
Now, above algorithm can be implemented in any kind of programming language.
Programs
- A program is implementation of algorithm in any programming Language, which in our case is Python.
- You can also say it is sequence of instructions given to computer to execute and solve a problem.
Example
Suppose you want to implement above algorithm example in Python following will be the code that you need to type in IDLE.
>>>a=5
>>>b=2
>>>x=a+b
>>>print(x)
7 // This is the result of a+b which is saved at x variable location.
I hope you understood difference between Program and Algorithm.
To solve any problem in real life you should make an algorithm first which will tell you steps to implement it.
Then just replicate the algorithm in any programming language you are using (eg: Python)
If you have any questions just Contact Me.
Thank you....
Comments
Post a Comment