成人快手

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.

Programming is done on a computer, and is usually the translation of an algorithm into a language the computer can understand.

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
Addition (plus)+
Subtraction (minus)-
Multiplication*
Division/
Arithmetic processAddition (plus)
Programming equivalent+
Arithmetic processSubtraction (minus)
Programming equivalent-
Arithmetic processMultiplication
Programming equivalent*
Arithmetic processDivision
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 (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