3.14 to 3.15

  • A software library contains procedures that can be used in the creation of new programs.
  • Existing segments of code can come from internal or external sources, ie. libraries or previously written code.
  • The use of libraries simplifies the task of creating complex programs.
  • Application program interfaces (APIs) are specifications for how the procedures in a library behave and can be used.
  • Documentation for a library or API is necessary in understanding the key behaviors provided by the API/library and how to utilize them in your work.
Defining a Library
  • A library is a collection of code from an external source that can be used to add functionality to a program.
  • Libraries are very useful, as they can be used to save time and effort in the development process.
  • Libraries are usually included in a program using a special keyword called "import" This keyword tells the program to look for the library and use its code.
Randomization

1) Randomization generates a value between two numbers. For example RANDOM(1,3) may result as 1 or 2 or 3, either one of those.

2) Now if we look into our day to day life we can see that randomization is all around us.

import random

answer1 = random.randint(0,3)
answer2 = random.randint(1,8)
answer3 = answer1 + answer2
print(answer3)
10

Use "Pip install ___" for new libraries

import random

num = random.randint(1,2)

if num == 1:
    print("Head")
elif num == 2:
    print("Tails")
Head

Some Essential Knowledge that you need to know

  • RANDOM (a,b) will provide you with a random integer between the numbers a-b
  • Ex. RANDOM (7,18) can provide you with the number 13.
  • Using a random generator means each result can come out as different.