Concept Flow - Arithmetic operators
Start
Read operands
Choose operator
Perform calculation
Store/Display result
End
This flow shows how arithmetic operators take two numbers, perform a calculation, and give a result.
Jump into concepts and practice - no test required
a = 10 b = 3 sum = a + b product = a * b result = a / b
| Step | Expression | Operands | Operation | Result |
|---|---|---|---|---|
| 1 | a = 10 | - | Assign 10 to a | a=10 |
| 2 | b = 3 | - | Assign 3 to b | b=3 |
| 3 | sum = a + b | a=10, b=3 | Addition | sum=13 |
| 4 | product = a * b | a=10, b=3 | Multiplication | product=30 |
| 5 | result = a / b | a=10, b=3 | Division | result=3.3333333333333335 |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | After Step 5 |
|---|---|---|---|---|---|---|
| a | undefined | 10 | 10 | 10 | 10 | 10 |
| b | undefined | undefined | 3 | 3 | 3 | 3 |
| sum | undefined | undefined | undefined | 13 | 13 | 13 |
| product | undefined | undefined | undefined | undefined | 30 | 30 |
| result | undefined | undefined | undefined | undefined | undefined | 3.3333333333333335 |
Arithmetic operators perform basic math on numbers. Common operators: + (add), - (subtract), * (multiply), / (divide). Operands are numbers or variables. Result is stored or used immediately. Division always returns a float in Python. Use parentheses to control order.
% gives the remainder after division, // gives the floor division result, ** is for power, and + is for addition.%, which returns the leftover part after dividing two numbers.** to calculate powers, so 5 ** 3 means 5 to the power of 3.5 ^ 3 is bitwise XOR, 5 ^^ 3 is invalid syntax, and pow(5, 3) is a function call but not an operator syntax.result = 17 // 4 print(result)
// divides and returns the largest whole number less than or equal to the result.num = 10 result = num % 0 print(result)
% cannot divide by zero; it causes an error.ZeroDivisionError at runtime.side. Which expression correctly uses arithmetic operators to do this?side ** 2 calculates side to the power of 2, which is correct for area.