PYTHON PROGRAM • OPERATORS & NUMBERS
Demonstrate Arithmetic Operators in Python
Compare addition, subtraction, multiplication and true division using two Python integers.
PROBLEM UNDERSTANDING
Input and expected output
No input required
22 12 85 3.4
COMPLETE PYTHON PROGRAM
Complete Python implementation
a, b = 17, 5 print(a + b, a - b, a * b, a / b)
CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
22 12 85 3.4
PROGRAM EXPLANATION
Algorithm and explanation
- Assign a = 17 and b = 5; this example does not read keyboard input.
- Evaluate a + b = 22, a - b = 12 and a * b = 85.
- Evaluate a / b = 3.4; Python true division returns a float for these integer operands.
- print displays the four results in order, separated by spaces.
The output 22 12 85 3.4 follows the order of the four expressions passed to print. Changing a or b changes the results without changing the operator meanings. The / operator performs true division, while // performs floor division: 17 // 5 is 3, but -17 // 5 is -4 because the result is rounded toward negative infinity. Dividing by zero raises ZeroDivisionError. The O(1) label describes this fixed-size demonstration; arithmetic on arbitrarily large Python integers can require increasing time and memory.
EFFICIENCY
Time and space complexity
O(1)
O(1)
DEBUGGING CHECKLIST
Common mistakes
Do not confuse / with //: they have different results and meanings.
Set b to a non-zero value before evaluating a / b.
Predict results in expression order; print does not reorder them.
