Hack #1

  • Write a program that uses a library/libraries in any sort of manner.
  • Explain your work/code:
    • this code below uses the pre-exisiting library "random" to generate a random number
    • it uses the keyword "input" to include it in the code
    • the random number is then used to see if you "win" the game or not
import random
number = random.randint(0,100)
print("you're random number is",number)
if number == 21:
    print("you win!")
else:
    print("better luck next time :(")
you're random number is 89
better luck next time :(

Hack 2

  • Define what an import random function do:

    • an import random function would import the contents of the pre-existing random library so that you could use it in your code
  • List a few other things that we can import other than random:

    • you can import more than just random. For example, you can import flask, math, or Numpy (a mathematical library).
import math
number = input("what number do you want to find the square root of?")
square_root = math.sqrt(int(number))
print("The square root of",number,"is",square_root)
The square root of 36 is 6.0

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?:

    • any number greater than or equal to 12 and less than or equal to 20 can be printed. (12,13,14,15,16,17,18,19,20)
import random
landed_on = random.randint(1,8)
if landed_on <= 3:
    color = "green"
elif 4<= landed_on <= 5:
    color = "blue"
elif landed_on == 6:
    color = "purple"
elif landed_on == 7:
    color = "red"
elif landed_on == 8:
    color = "orange"

print("your color is", color)
your color is blue