We can use math to change numbers around and edit our data. You can use these operators on an integer and another integer, on a float and another float, or on a combination of the two.
Format:
Operator
Usage (Code Example)
Note
Addition (+)
Example
x = 5
y = 3
print(x + y) # prints 8
View code on GitHub.
Subtraction (-)
Example
x = 5
y = 3
print(x - y) # prints 2
View code on GitHub.
Multiplication (*)
Example
x = 5
y = 3
print(x * y) # prints 15
View code on GitHub.
(Floating Point) Division (/)
Example
x = 15
y = 3
print(x / y) # prints 5.0
x = 5
y = 3
print(x / y) # prints 1.6666666666666667
View code on GitHub.
This type of division gives a floating-point number (float) with a decimal remainder (the remainder divided by the divisor is the decimal)
(Floor) Division (//)
Example
x = 5
y = 2
print(x // y) # prints 2
View code on GitHub.
This type of division gives you an integer and ignores any remainder
Modulus (%)
Example
x = 14
y = 3
print(x % y) # prints 2
View code on GitHub.
This gives you the remainder after dividing the 2 numbers.
Exponent (**)
Example
x = 2
y = 3
print(x ** y) # prints 8
View code on GitHub.
It is equivalent to x to the power of y
Ask the user for a number, and store it in a variable called x. Divide the number x by 5, then add 2 to it, then store it in a variable called y. Print the result (y).
💻Template code