Lesson Notes 3.14 and 3.15
Lesson Notes
import math
math.sqrt(64)
This is an example of using the library math. It is mind of like the square root function was already existing, which made it easier to use and we didn't have to code much
import random
flip = random.randint(1,2)
if flip == 1:
print("Heads")
else:
print("Tails")
# Try this code for yourself!
This is an example of a random library that is used to randomly generate the output, which makes sure that the output is different every time.
- Define what an import random function do: It basically provides function that are already there instead of having to type in a bunch of code to compensate for that same function.
- List a few other things that we can import other than random
- import math
- import flask
- import numpy
import random
spin = random.randint(1,8)
if spin <= 3:
print("green")
elif spin <= 5:
print("blue")
elif spin <= 6:
print("purple")
elif spin <= 7:
print("red")
elif spin <= 8:
print("orange")
This is another example of a random generator and it will print these colors randomly