You can do that as something as follows:
from random import shuffle
list_of_questions = ['A', 'B', 'C', 'D', 'E', and so on]
shuffle(list_of_questions)
question = list_of_questions.pop()
The .pop()
method deletes the last question from the list and returns it. In this case it will always be randomized since that is what shuffle
does therefore it doesn't matter that it is always the last.
For example:
>>> some_list = [1,2,3,4,5]
>>> shuffle(some_list)
>>> some_list
[4,2,5,1,3]
>>> some_list.pop()
3
>>> some_list
[4,2,5,1]
[NOTE]
I also suggest that you create a separate text file with all the questions (1 question per line). Using python, you an easily read in those questions and at a future date, you can also easily delete or add new questions without much effort.
Example:
#questions.txt Remember, your questions file will need to be in the same directory as your python script
What is ..?
Who is ..?
Where is ..?
Why is ...?
#Start of your python code
questions = [line.strip() for line in open('questions.txt'. 'r')]
>>> print questions
['What is ...?', 'Who is ...?', 'Where is ...?', 'Why is ...?']
>>> from random import shuffle
>>> shuffle(questions)
>>> print questions.pop()
Where is ...?
>>> print questions
['What is ...?', 'Who is ...?', 'Why is ...?'] #Note the question that was taken is gone from the list. Thanks to the .pop() method