datetime is just the beginning. There are hundreds of Python modules that you can use. Another one of the most commonly used is
random which allows you to generate numbers or select items at random.
random, we’ll be using more than one piece of the module’s functionality, so the import syntax will look like:
We’ll work with two common
random.choice()which takes a list as an argument and returns a number from the list
random.randint()which takes two numbers as arguments and generates a random number between the two numbers you passed in
Let’s take randomness to a whole new level by picking a random number from a list of randomly generated numbers between 1 and 100.
In script.py import the
Create a variable
random_list and set it equal to an empty list
Turn the empty list into a list comprehension that uses
random.randint() to generate a random integer between 1 and 100 (inclusive) for each number in
Create a new variable
randomer_number and set it equal to
random_list as an argument.
randomer_number out to see what number was picked!