Math
Introduction
You can use Python to solve Math problems!
Python Math Operators
Symbol
Operation
+
addition
-
subtraction
*
multiplication
/
division
//
integer division
**
power or exponent
%
remainder or modulus
()
parenthesis
Order of Operations Precedence
Symbols
Parentheses
()
Exponent
**
Multiplication, Division (from left to right)
* / //
Addition, Subtraction (from left to right)
+ -
When doing Math in Python, you must specify multiplication when you want multiplication. For example: 3(4 + 2) instead of 3 * (4 + 2) will result in an error.
import math
Python has a number of builtin math methods.
import math
# square root
print(math.sqrt(2))
# pi
print(math.pi)
Examples
Write Python code that does the following:
Assign the variable bday to the month of your bday.
Multiply bday by 5.
Add 6 to bday.
Multiply bday by 4.
Add 9 to bday.
Multiply bday by 5.
Add the number number of the day of your bday.
Subtract 165 from bday.
Print the value of bday.
# Example birthday of 1/1
bday = 1
bday = bday * 5
bday = bday + 6
bday = bday * 4
bday = bday + 9
bday = bday * 5
bday = bday + 1
bday = bday - 165
print(bday)
Last updated
Was this helpful?