Module 3 - Section 2 - Lists

3.2.5 - Random

Random is a function that creates random numbers. It is not in the core of Python but in a library (the random library). In order to use it first we have to import the library. Copy the following code to Thonny and save it as Randomize.

import random print (random.randrange(1,50))


If we wanted to randomly select a number between 50 and 80 then the code should be :

import random print(random.randrange(50,81))


You can explore random function and how to use it in several cases here

To combine lists with random we will create a list of 20 random numbers from 1 to 80 like in the kino game.

Copy the following code to Thonny's editor and save it as kino.py.


Are the numbers in the list unique?