xxxxxxxxxx
Arithmetic:
operator | name | example |
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y
Comparison:
Operator | Name | Example |
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Assignment:
Operator | Example |
= x = 5
+= x += 3
-= x -= 3
*= x *= 3
/= x /= 3
%= x %= 3
//= x //= 3
**= x **= 3
&= x &= 3
|= x |= 3
^= x ^= 3
>>= x >>= 3
<<= x <<= 3
xxxxxxxxxx
#math in python: Multiple action
x = int(input("Type value for x: "))
y = int(input("Type value for y: "))
z = int(input("Type value for z: "))
print(x / y + z)
#you need multiple solution at once.
#Go ahead and copy the code to your
# .py script to see the results.
xxxxxxxxxx
import math
# Basic operations
addition = 2 + 3
subtraction = 5 - 1
multiplication = 4 * 2
division = 10 / 3 # Returns a float
# Advanced operations
power = pow(2, 3) # Calculates 2^3
square_root = math.sqrt(16)
absolute_value = abs(-7)
rounding = round(4.7)
# Trigonometry
sine = math.sin(math.radians(45))
cosine = math.cos(math.radians(60))
tangent = math.tan(math.radians(30))
# Constants
pi = math.pi
euler_number = math.e
# More complex functions available in the math module
print(f"Addition: {addition}")
print(f"Subtraction: {subtraction}")
print(f"Multiplication: {multiplication}")
print(f"Division: {division}")
print(f"Power: {power}")
print(f"Square Root: {square_root}")
print(f"Absolute Value: {absolute_value}")
print(f"Rounding: {rounding}")
print(f"Sine: {sine}")
print(f"Cosine: {cosine}")
print(f"Tangent: {tangent}")
print(f"Pi: {pi}")
print(f"Euler's number: {euler_number}")
xxxxxxxxxx
x = int(10)
y = int(5)
print(x + y)
#you need to define integer extra otherwise
# python will count this as a str and won't work.
#copy the code to your py script to see the accurate result.
xxxxxxxxxx
#math in python: Multiple action
x = int(input("Type value for x: "))
y = int(input("Type value for y: "))
z = int(input("Type value for z: "))
print(x * y + z)
#you need multiple solution at once.
#Go ahead and copy the code to your
# .py script to see the results.