Hack #1:

Import Math allows you to use a library that already exists and use can use it to perform functions like the square root function below.

import math

math.sqrt(256)
16.0

Hack #2:

  • 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
  • Write a few lines of code that implements the import function
import random
i = 1
while i < 5:
    choose = random.randint(1,20)
    print(choose)
    i += 1
6
3
6
18

Hack #3:

  • For your hacks you need to create a random number generator that will simulate this situation:
  • There is a spinner divided into eight equal parts. 3 parts of the spinner are green, two parts are blue, one part is purple, one part is red, and one part is orange. How can you simulate this situation using a random number generator.

  • Also answer this question: What numbers can be outputted from RANDOM(12,20) and what numbers are excluded? I think number 12-20 will be outputted and every other number other than those numbers will be excluded.

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")
green