3.14 Hacks

import random

number = random.randint(0,10)

if number>3:
    print("Team Baddies for life")
elif number>6:
    print("I can't wait for break!")
else: 
    print("APCSP is okay")
Team Baddies for life

In my code, I use import random to allow me to access the "random" library. This allows the to choose a random number, which decides which statement will print. If the random number chosen is less than 3, "Team Baddies for life" will print. If it is less than 6, "I can't wait for break!" will print. If any other is chosen, "APSCP is okay" will print.

3.15.2 Hacks

a.

An import random function generates a random number between two integers. When calling the random functi.on to get a random number, you will set two parameters to set a boundary of numbers it can choose from.

b.

You can import math to use commands like math.sqrt to find the square root of integers. Import flask and colorama are two more imports.

NOTE

You can use "pip install" to install a library you don't have yet.

3.15.2 Hacks

import random
spinner = random.randint(1,8)

if spinner<=3:
    print("green")
elif spinner<=5:
    print("blue")
elif spinner==6:
    print("purple")
elif spinner==7:
    print("red")
else:
    print("orange)")
blue
What numbers can be outputted from RANDOM(12,20) and what numbers are excluded?
  • Numbers 12 through 20 will be outputted, all other numbers outside this range are excluded.