Files

4.0 KiB

Basic Arithmetic

In [ ]:
# Addition
2+1
In [ ]:
# Subtraction
2-1
In [ ]:
# Multiplication
2*2
In [ ]:
# Division
3/2
In [ ]:
# Floor Division
7//4
In [ ]:
# Modulo
7%4

Arithmetic continued

In [ ]:
# Powers
2**3
In [ ]:
# Can also do roots this way
4**0.5
In [ ]:
# Order of Operations followed in Python
2 + 10 * 10 + 3
In [ ]:
# Can use parentheses to specify orders
(2+10) * (10+3)

Variable Assignments

In [ ]:
# Let's create an object called "a" and assign it the number 5
a = 5
In [ ]:
# Adding the objects
a+a
In [ ]:
# Reassignment
a = 10
In [ ]:
# Check
a
In [ ]:
# Check
a
In [ ]:
# Use A to redefine A
a = a + a
In [ ]:
# Check 
a
In [ ]:
# Use object names to keep better track of what's going on in your code!
my_income = 100

tax_rate = 0.1

my_taxes = my_income*tax_rate
In [ ]:
# Show my taxes!
my_taxes