Unit 14 and 15 Notes and Hacks
Following along lesson plan Unit 14 and 15 while taking notes and doing the Hacks.
Notes
Section 14 Libaries and Documentation
Vocabulary
- Documentation - text that explains what, how, or the why of your code.
- Libraries - collection of prewritten code/procedures that coders can maximize to their efficiency.
- Application Programming Interface (API) - a type of software through several computers are able to communicate information to each other. Gives specific directions for how procedures that reside in these APIs can be used.
Key Point
Reusing code is beneficial.
Section 15 Random Values Pt. 1
Randomization
- examples of randomization are picking a card, rolling a dice, or a gumball machine.
- RANDOM(1,3) would display any numbers 1, 2, or 3
Section 15 Random Values Pt. 2
Syntax
- randint
- randrange
Randint
- randint(start, stop)
Randrange
- randrange(start, stop, step)
Hacks
Multiple Choice
1)
- B, because a and b are used as numbers to generate random integers. and RANDOM randomizes the number in which you set a to b as.
2)
- A, because x, y, and z all represent different things such as x being start, y being stop, and z being step. X is the starting number, Y is the stop number, and Z is the steps.
3)
- B, because instead of the command being random.random, the command would be just random() with nothing in the paranthesis. You can’t random a random.
Short Answer Questions
1) The advantage of a library such as the College Board APCSP Exam Reference Sheet, is that a library shows how code should be and is used.
2) The first step of the code is to import random library to use throughout the code. Next, the code asks for everybody names in which the person in which the codes waits for the user input to use as list. From there, the code analyzes how many people are in the list and uses a random number generator to find the name via a index from the list. Then that person is set as person_who_will_pay and the code prints the name of the person who will pay.
Coding Challenges!
- Create a program to pick five random names from a list of at least 15 names

- Create a program to simulate a dice game where each player rolls two fair dice (6 sides); the player with the greater sum wins
