ARITHMATIC EXPRESSION EXAMPLES IN PYTHON
ARITHMATIC EXPRESSION EXAMPLES IN PYTHON
1.Addition:
CODE:
result = 5 + 3 print(result)
Output:8
2.Subtraction:CODE:
result = 10 - 4 print(result)
Output: 6
3.MULTIPLICATION:
CODE:
result = 6 * 2
print(result)
Output: 12
4.Division:
CODE:
result = 15 / 3
print(result)
Output: 5.0 (floating-point division)
5.Integer Division (Floor Division):
CODE:
result = 15 // 3
print(result)
Output: 5 (integer division, discards the fractional part)
6.Modulo (Remainder):
CODE:
result = 15 % 7
print(result)
Output: 1 (remainder of the division 15/7)
7.Exponentiation:
CODE:
result = 2 ** 4
print(result)
Output: 16 (2 raised to the power of 4)
8.Mixed Operations:
CODE:
result = 4 + 6 * 2 - 8 / 4
print(result)
Output: 15.0 (follows the order of operations: multiplication/division before addition/subtraction)
These are just a few examples of arithmetic expressions in Python. You can combine operators and values to perform various calculations based on your requirements.
Comments
Post a Comment