Part 2 Arithmetic Operators
Part 2 Arithmetic Operators
operators
Module 2 / Operators and Decisions
Arithmetic Operators
Arithmetic operators
+ - * /
addition subtraction multiplication division
** // %
integer
exponent remainder
division
Arithmetic Operators
Arithmetic operators
3+2=5 7-3=4
addition subtraction
2*4=8 6/3=2
multiplication division
Some examples
OperadoresOperators
Arithmetic Aritméticos
Exponent
3 ** 2 = 9 2 ** 3 = 8
exponent exponent
32 = 9 23 = 8
It is like this in math It is like this in math
Arithmetic Operators
Integer Division
5 / 2 = 2.5 5 // 2 = 2
Regular division Integer division
17 / 6 = 2.833.. 17 // 6 = 2
Regular division Integer division
Remainder or Modulus
33 % 6 = 3
Remainder
11 % 2 = 1
Remainder
Remainder or Modulus
100 % 8 = 4 25 % 5 = 0
Remainder Remainder
Parentheses
()
Parentheses
(3+2) * 2 = 10
Parentheses use
Priority order
They are first priority operations. Operations within parentheses are evaluated
() first. If nested parentheses are found, (one inside the other), the expressions
in the innermost parentheses are evaluated first. If multiple parentheses are
found on the same level, they are evaluated from left to right.
( 5 + 4 ) + ( 3 * 2) ( 25 /5 ) ** 2
8 + 3 * 11 - 2 ( 2 ** 2 ) ** 2
8%3+1 ( 25 % 3 ) * ( 5 % 3 )
15 / 3 * 2 ( 51 % 5 ) * 5 // 2 + 4
12.5 + 12.5 + 1 5 / 2 + 10 // 3 / 3
Arithmetic Operators
Converting Expressions
The parentheses are used only to group values or operations. Unlike math or physics,
parentheses do not represent multiplication.
(4 X 5)2
--------------------- (4 * 5)**2 / ( ( 2 * 3 )**3 + ( 5 * 2 ) * (3 * 3)**2 )
( 2 X 3 )3 + ( 5 X 2 )(3 X 3)2
Mathematics Python
Arithmetic Operators
Converting Expressions
A= P*(1+r/n)**(n*t) A= P*(1+r/n)**(n*t)
Finance Python
Arithmetic Operators
Calculating Areas
Area of a Triangle
Python
Arithmetic Operators