Arithmetic

is writing computer code to create a program, to solve a problem. are created to implement . Algorithms can be represented as or a , 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.

Basic arithmetic

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 processProgramming equivalent
Subtraction (minus)-
Multiplication*
Division/

Computers can be programmed to carry out calculations – so long as the correct formulas to use are known. Some simple mathematical examples in (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