Unit 3.14 & 3.15
- library contains procedures that can be used in the creation of new programs, saves time and effort
- simplifies the task of creating complex programs.
- Application program interfaces (APIs)
#instead of writing code to find the square root, the sqrt()
# function in the math library gives the answer with the number in the argument
import math
math.sqrt(64)
# list of people can be indexed to get a random person in the list of people
import random
people = ["Grace", "Claire", "Harry", "Taylor", "Annika", "Jane"]
num = random.randint(0,6)
print(num)
print(people[num])
# one part is purple, one part is red, and one part is orange
import random
spinner = ["green", "green", "green", "blue", "blue", "purple", "red", "orange"]
index = random.randint(0,7)
print("Your spinner spun: " + spinner[index])
Also answer this question: What numbers can be outputted from RANDOM(12,20) and what numbers are excluded?
random(12,20) can produce outputs 12, 13, 14, 15, 16, 17, 18, 19, 20