Numbers and Math
Last updated
<class 'int'>
<class 'float'># Demonstrates different math operations
using f-strings
n1 = 7 # First number
n2 = 3 # Second number
# Output results of different math operations
print(f"{n1} + {n2} = {(n1 + n2)}") # Addition
print(f"{n1} - {n2} = {(n1 - n2)}") # Subtraction
print(f"{n1} * {n2} = {(n1 * n2)}") # Multiplication
print(f"{n1} / {n2} = {(n1 / n2)}") # Division
print(f"{n1} // {n2} = {(n1 // n2)}") # Floor Division
print(f"{n1} ** {n2} = {(n1 ** n2)}") # Power/Exponent
print(f"{n1} % {n2} = {(n1 % n2)}") # Modulo/Remainder7 + 3 = 10
7 - 3 = 4
7 * 3 = 21
7 / 3 = 2.3333333333333335
7 // 3 = 2
7 ^ 3 = 343
7 % 3 = 1# compare.py
# Demonstrate comparison operators
# Assign values to variables using parallel assignment
c1, c2, c3, c4 = 25, 50, 75, 50
print(f" c1 = {c1}, c2 = {c2}, c3 = {c3}), c4 = {c4}")
# Output results of different comparison operations
# Testing equality
print(f"c1 = c3 is {(c1 == c3)}")
# Changing values using abbreviated assignment operators
c1 *= 3 # Shorthand for c1 = c1 * 3
c4 += 1 # Shorthand for c4 = c4 + 1
print(f"c1 = {c1}, c2 = {c2}, c3 = {c3}, c4 = {c4}")
# Testing less than and greater than
print(f" c1 < c2 is {(c1 < c2)}")
print(f" c4 <= c2 is {(c4 <= c2)}")
print(f" c1 > c2 is {(c1 > c2)}")
print(f" c3 >= c2 is {(c3 >= c2)}") c1 = 25, c2 = 50, c3 = 75), c4 = 50
c1 = c3 is False
c1 = 75, c2 = 50, c3 = 75, c4 = 51
c1 < c2 is False
c4 <= c2 is False
c1 > c2 is True
c3 >= c2 is True