Notes

Software libraries contain procedures used in creating novel programs Libraries and prewritten code can make writing algorithms much easier Libraries simplify complex programs APIs(application program interfaces) specify how procedures in libraries should behave and be utilized Reading documentation makes it much easier to understand how to use libraries/APIs Useful random functions include: random.randint(a, b): generates a random number. The values of a and b are required, as they are the start and stop values, placing an inclusive limit on the number to be generated. C is the step, which is optional, and is the interval at which the random numbers are generated at random.randrange(a, b, c): generates a random number. The values of a and b are required, as they are the start and stop values, placing an inclusive limit on the number to be generated. C is the step, which describes what kind of multiple can be generated. The potential value starts at a, or is a a + a multiple of c, and is less than b. random.shuffle: shuffles a list randomly to scramble contents

Vocab Documentation: Text that explains the what, how, or why of your code. Libraries: A collection of prewritten code or procedures that coders can use to maximize their efficiency Application Programming Interface: A type of software through several computers are able to communicate information amongst eachother

Multiple Choice Problems

B. A random integer from a to b inclusive The random(a, b) function is inclusive, and generates a number. This means that the random integer will be from a to b and inclusive.

A. x = start, y = stop, z = step X and Y describe the range in random(x, y, z). These are both required. Z is optional, and is the step, and shows the intervals for random numbers.

A. random.item random.item does not exist. random.random generates a float between 0 and 1. random.shuffle randomly shuffles a list. random.randint generates a random integer.

Short Answer Questions

  1. Using libraries allows users to access and reuse pre-written code. This allows algorithms to be made more efficient. Additionally, there are many libraries which are created for multiple different purposes, which makes it easier for programmers to create more complex algorithms.

  2. First, the code segment imports the random library for use. Then, the program takes in names from user input, and puts them into a list(names). Then, the variable num_items finds the length of the list of names. The random_choice variable generates a random number which will be an index of the list. random_choice makes use of the random.randint function and generates a value from 0 to the maximum index(length of list minus 1). Then the program finds the person who is associated with the randomly generated value. Finally, the program prints that individual’s name.