Vocab

Documentation: The what, how, or why of the code Libraries: Prewritten code or procedures that can be used to maximize efficiency API: Data stored in a database that can be accessed via code

Notes

  • Documentation is understanding the purpose of a procedure when it gets too long

(1) Reflection

Thorough notes or summary that reflects understanding of today’s lesson.

(2) Multiple Choice

What does the random(a,b) function generate? A. A random integer from a to be exclusive

B. A random integer from a to b inclusive. Explanation : This is becuase the random integers from a to be pick something within these parameters leaving it to be answer B

C. A random word from variable a to variable b exclusive.

D. A random word from variable a to variable b inclusive.

What is x, y, and z in random.randrange(x, y, z)? A. x = start, y = stop, z = step EXPLANATION : This is the answer as random rad range gives you a number from one of these sets so in this case x = start y= stop z= step

B. x = start, y = step, z = stop

C. x = stop, y = start, z = step

D. x = step, y = start, z = stop

Which of the following is NOT part of the random library? A. random.item This isnt not a known function in random librabries

B. random.random

C. random.shuffle

D. random.randint

(3) Short Answer Questions

What is the advantage of using libraries? ANSWER: The advantage of using libraries is its a faster and more easier way to get code rather than having to write it and test it.

Write a thorough documentation of the following code.

import random

names_string = input(“Give me everybody’s names, seperated by a comma.”) names = names_string.split(“,”)

num_items = len(names)

random_choice = random.randint(0, num_items - 1)

person_who_will_pay = names[random_choice]

print(f”{person_who_will_pay} is going to buy the meal today!”) is going to buy the meal today! (4) Coding Challenges!

REQUIRED: Create programs in python to complete the two task</p>

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