<jupyter_start><jupyter_text>Modules---Modules are collection of code that is available for us to call upon when needed. This helps us program while not reinventing the wheel. What are Modules?A module is a Python code with a sole purpose that it exists to:- Group related code- Extend the capabilities of your current Python code by importing it to your own code- Avoid creating solutions that already existThe two modules that we will focus on will be: __math__ and __random__.There are a lot modules that exists beyond what Python 3 offers (pandas and plotly to name a few). These can be installed to your computer. Special KeywordsTo use any modules, we need the following 3 keywords:- ```import```- ```from```- ```as``` ```math``` moduleThe math module allow us to access more built-in functions to access some mathematical functions that basic python does not include. You can find the entire offering of the math module [here](https://docs.python.org/3/library/math.html).```pythonmath.ceil(x) → rounds up the parameter x to its closest integermath.floor(x) → rounds down the parameter x to its closest integermath.fabs(x) → returns the absolute (non-negative) value of xmath.factorial(x) → returns the calculation of x factorial (x!)math.gcd(a,b) → returns the greatest common divisor of parameters a and bmath.log(x) → returns the natural log (ln) of xmath.log2(x) → returns the base 2 log of xmath.log10(x) → returns the base 10 log of xmath.pow(x,y) → returns to power of x to the exponent of ymath.sqrt(x) → returns the square root of xmath.sin(x) → returns the sine of xmath.cos(x) → returns the cosine of xmath.tan(x) → returns the tangent of xmath.asin(x) → returns the arc sine of xmath.acos(x) → returns the arc cosine of xmath.atan(x) → returns the arc tangent of xmath.degrees(x) → returns the conversion of x radians to degreesmath.radians(x) → returns the conversion of x degrees to radians```<jupyter_code># Math Module Example
# Just using only the import statement

import math # this gives access to the entire module

# to use any of the functions seen above, we need the "math." prefix

# Greatest common divider
a = 144
b = 252

result = math.gcd(a,b)
print('The GCD of', a, 'and', b, 'is:', result)
# Math Module Example 2
# Using from ... import ... as 
# from allow us to target a single function/item from our importing module
# as allow us to rename the imported function

from math import sqrt as squareRoot # we have now only imported square root function and renamed it
# this way, we don't need the 'math.' prefix

print('The square root of 25 is:', squareRoot(25))<jupyter_output>The square root of 25 is: 5.0<jupyter_text>```random``` moduleThe random module is a way to add random-like functionality to our code. Generation of random number is very fun way concept especially in game development.You can find the entire offering of the random module [here](https://docs.python.org/3/library/random.html).```random.seed(x) → the parameter x (an integer) is optional …    The seed function exists to help us generate a more predictable randomness.     If the seed() is given an integer, the program will generate the random same number every time.   random.random() → This function requires no parameters.     Every time this function is called, it will generate a random float from 0.0 inclusively to 1.0 exclusivelyrandom.randrange(a,b,c) → This function helps to generate random numbers, it will behave differently based on the number of arguments    random.randrange(x) → Generates random integers from 0 to x, but not including x    random.randrange(a,b) → Generates random integers from a to b, but not including b    random.randrange(a,b,c) → Generates random integers from a to b; not including b, and     the available values will be a set of values from parameter a increasing by parameter crandom.randint(a,b) → Behaves the same way as random.randrange(a,b+1)random.choice(sequence) → Returns a random value from the parameter sequence    if the sequence is a string → returns a single character    if the sequence is a list → returns a single item```<jupyter_code># Example ... just using random()

import random
print('Random number generated:', random.random())

# Whenever this program runs, it should generate a new random floating point value
# Example 2
# Using randrange to generate random integers

from random import randrange # if you like what the function is called, as statement is not required

value1 = randrange(10) # Value 1 now contains a random value from 0 to 9 inclusively
value2 = randrange(1,101) # Value 2 now contains a random value from 1 to 100 inclusively

value3 = randrange(10, 1000, 3) 
# Value 3 now contains a random value of X such that the list of numbers to choose from goes from 10 to 1000
# However, the interval between each number is 3 units away

print('value1:', value1)
print('value2:', value2)
print('value3:', value3)
# Example 3
# Using choice

from random import choice

word = 'The Lazy Dog sleeps in his crate.'
array = ['Oranges', 'Watermelons', 'Apples', 'Kiwis', 'Bananas']

print('Random letter from word:', choice(word))
print('Random item from array:', choice(array))<jupyter_output>Random letter from word: a
Random item from array: Watermelons
{'fraction_non_alphanumeric': 0.07790476190476191, 'fraction_numerical': 0.013523809523809523, 'mean_word_length': 4.5625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '363156', 'license': 'MIT', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1397, 'n_words': 778, 'path': '7 Modules.ipynb', 'repo_name': 'mrparkonline/py_basics', 'size': '5250'}