Tuesday, 31 August 2010

Python - Simple Math in Python

In python you can do simple math tasks, like 1+1 or 10/2, to test these out open up the IDLE and type:

>>>2+1
3


This looks very simple (and is), but we can do more complicated things like:

>>>(55**4-6) / 3
3050206
To give you an idea of what math you can do here is a table:

Table 1 - Python Math operators
command name example output
+ Addition 4+5 9
- Subtraction 8-5 3
* Multiplication 4*5 20
/ Division 19/3 6
% Remainder 19%3 5
** Exponent 2**4 16

No comments:

Post a Comment