Hacks 3.14.1 Write a program that uses a library/libraries in any sort of manner. Explain your work/code
import random
import math
num = random.random()*100
print(math.floor(num))
This code uses the math library and the random library to get a random whole number between 0 and 100
Hacks 3.15.1 Write a few lines of code that implements the import function
import math
math.cos(3.14159)
Define what an import random function do
- The import random function finds the random library and allows the user to have access to many different functions
List a few other things that we can import other than random
- We can import math and this gives us access to many different operators and math functionality
Hacks 3.15.2 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?
import random
import math
def generator(range):
return math.floor(random.random()*range)
number = generator(8)
if number <= 3:
print("green")
elif number > 3 and number <6:
print("blue")
elif number ==6:
print("purple")
elif number==7:
print("orange")
elif number==8:
print("red")
Also answer this question: What numbers can be outputted from RANDOM(12,20) and what numbers are excluded?
- RANDOM(12,20) will include all numbers between 12 and 20 including 12 and 20. According to Savan