Random allows you to choose a random item from lots of sources.
To use random you need to inport it at the top of your program
Simple random whole number
Random Numbers used in a quiz
You can try this code by downloading randomnumbertest.py below
Other useful areas contained in this code variables print if else Maths Operations
Random Item from a list
Clearest way to do this is
Or you could create the list inside the yourturn variable
It is your turn Mary
Mary could be replaced by John, Sheila or Mark
Find out more about a list
Random item from a file
Make sure the file you have created is in the same folder as the Python program you are writing.
Make sure each object is on a separate line.
Save the file as a .txt file.
In this example the file is films.txt
Note you must open and close the text file
You can download this file as files.py and the films.txt below (You must place them in the same folder)