Python 3.4 - Numbers

 Oh no, numbers!!!

+ add
- subtract
* multiply
/ divide

Don't forget your order of operations (i.e. 3 + 2 * 8 = 19, not 40.)

Parentheses take precedence! (i.e. (3 + 2) * 8 = 40, not 19.)

// drop the remainder
% give me the remainder only
** to the power of 3 (i.e. 5 * 5* 5 = 125 is the same as 5 **3)

**variables can be turned into numbers and vice versa (i.e. bacon = 5, therefore bacon + 5 = 10)***

num = 3print(type(num))

num2 = 2.3print(type(num2))

num3 = 3 + 2
print(num3)


print(3 *3)

print(3/2)

# drops the remainder
print(3//2)

print(3**2)  # this is equal to 3 x 3 or 3^2
print(3**3)  # this is 3^3 or 3 x 3 x 3
print(2%2)  # this is giving the remainder, which would be zero
for x in range(10):
    if x % 2 == 0:
        print(x, 'these numbers have a remainder of 0 when divided by 2')
    else:
        print(x, 'these do not.')

# order of operations hold true in python
print(3 * 2 - 1)
print(3 * (3 + 1))

num4 = 1
num4 = num4 + 1
print(num4)

num5 = 1
num5 += 1
print(num5)

num6 = 2
num6 = num6 * 3
print(num6)

# rounding numbers
print(round(3.7))

print(round(3.75, 1))

# boolean operators determine if something is true or false
num7 = 3
num8 = 2
print(num7 == num8)

print(num7 != num8)

print(num7 > num8)

num9 = '100'num10 = '200'
print(num9 + num10) # this added two strings together but not quite
num11 = int(num9) # by adding the integer function to the nums we can now add them correctly. num12 = int(num10)

print(num11 + num12)








/Users/mattfassnacht/PycharmProjects/untitled10/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled10/math.py
<class 'int'>
<class 'float'>
5
9
1.5
1
9
27
0
0 these numbers have a remainder of 0 when divided by 2
1 these do not.
2 these numbers have a remainder of 0 when divided by 2
3 these do not.
4 these numbers have a remainder of 0 when divided by 2
5 these do not.
6 these numbers have a remainder of 0 when divided by 2
7 these do not.
8 these numbers have a remainder of 0 when divided by 2
9 these do not.
5
12
2
2
6
4
3.8
False
True
True
100200
300

Process finished with exit code 0

https://www.youtube.com/watch?v=hnxIRVZ0EyU&index=2&list=PL6gx4Cwl9DGAcbMi1sH6oAMk4JHw91mC_

Comments

Popular posts from this blog

Python 3.4 - Caesar Cipher

UML - Use Case Diagram