Notes

Libraries

  • Software libraries contain procedures that are used to create new programs
  • Existing segements of code can come from internal or external sources such as a library
    • Documentation for a library or api is essentail to understand key behaviors in your work.
  • Library: collection of code from an external source that adds functions and assets to a program
    • Are called using a special keyword, Import
  • To install a library, you can use “pip install _____” which is the name of the library.

  • Example: Math Library:

Randomization

  • “Import random” randomizes options that are inputted between parenthesis ().

#### distribution (used in statistics)

expovariate()	  |  Returns a random float number based on the Exponential distribution (used in statistics)

gammavariate()	  |  Returns a random float number based on the Gamma distribution (used in statistics)

gauss()	          |  Returns a random float number based on the Gaussian distribution (used in probability theories)

lognormvariate()  |  Returns a random float number based on a log-normal distribution (used in probability theories)

normalvariate()	  |  Returns a random float number based on the normal distribution (used in probability theories)

vonmisesvariate() |  Returns a random float number based on the von Mises distribution (used in directional statistics)

paretovariate()	  |  Returns a random float number based on the Pareto distribution (used in probability theories)

weibullvariate()  |  Returns a random float number based on the Weibull distribution (used in statistics)

RANDOM function

  • RANDOM(a,b) will give you a random integer between and including numbers a through b

  • Here is a code that I made, using RANDOM, which gives you the output of a coin flip:

Hacks

Hack 1: Write a program that uses a library and explain your code

  • As you can see, I have used the “math” Library by stating “import math”.
  • I then used “math.factorial” to get the factorial of the input which is 5. The factorial of 5 is 1 x 2 x 3 x 4 x 5 which = 120.
  • I then used python to print “The factorial of 5 is 120

Hack 2: define import random, and list other things we can import other than random.

  • Import Random command calls the “random” library which randomizes the values that are inputted between parenthesis ().
  • An example of this would be

  • There are many other libraries that you can import such as “math” that does calculations for you, “numpy” that is different math library that includes calculus. “pandas” can merge and index data for you.

Hack 3: Random number generator that simulates the situation: Also answer: What numbers can be outputed from RANDOM(12,20) and what can’t?

  • 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.

  • As you can see, I created this code that does a random number generator using “random.randint(1,8)” then uses that random number and prints a specific color based on the number that is outputted using “if statements”.
    • The spinner outputed “orange” meaning that the random number was 8.
  • The numbers that can be outputted from “RANDOM(12,20) are 12,13,14,15,16,17,18,19, or 20.
    • Anything besides those numbers are excluded.