Programmingis writing computer code to create a program, to solve a problem. Programs are created to implement algorithms. Algorithms can be represented as pseudocode or a flowchart, and programming is the translation of these into a computer program.
To tell a computer to do something, a program must be written to tell it exactly what to do and how to do it. In order to do this, you need to know how programs are constructed.
Arithmetic is used all the time in computer programs, so an understanding of how computers use arithmetic is useful. This table lists the common arithmetic processes with their programming equivalents:
|Arithmetic process||Programming equivalent|
Computers can be programmed to carry out calculations – so long as the correct formulas to use are known. Some simple mathematical examples in Python (3.x) are:
>>> print(5 + 7) 12 >>> print(7 - 5) 2 >>> print(5 * 7) 35 >>> print(35 / 7) 5.0
More complicated calculations can be performed too:
>>> print((5 * 2) + (4 - 3)) 11 >>> print((8 / 4) + (2 - 1)) 3.0