Multiple Choice Quiz With Randomising Answer Positions PYTHON 3.5.2
Question: I am creating a Que Card quiz in which a keyword from a text file is chosen at
random, the program should then show the correct definition along with 2 other
incorrect definitions that are in the text file as well. So far I have the
keyword, the correct definition and the 2 incorrect definitions stored inside
a list. Is there anyway that I can randomise the order of the items in the
list and randomise their positions when the user is answering the question. I
have tried to look this up but I can't find anything.

Example:

"Keyword is frog 1: Frogs are blue 2: Frogs are Green 3: Frogs are purple "
But then the next time the keyword frog comes up they will be in different
orders.

"Keyword is frog 1: Frogs are green 2: Frogs are blue 3: Frogs are purple "


Answer: Here's one possible approach based on `random.shuffle()`. I've use objects to
separate the question from the answers, and followed your convention that the
first answer provided in constructing the question is the correct one. I've
chosen to shuffle the indices rather than the answers themselves, just to
illustrate that it's possible to maintain the original inputs as-is and still
attain a random ordering.

    
    
    import random
    
    class Question:
        def __init__(self, q, a):
            self.q = q
            self.a = a
            self.order = [i for i in range(len(a))]
            random.shuffle(self.order)
    
        def query(self):
            print(self.q, [self.a[i] for i in self.order])
    
        def correct_answer(self):
            print("\tCorrect answer is", self.a[0])
    
    q1 = Question("Frogs are:", ["green", "red", "purple"])
    q1.query()
    q1.correct_answer()
    q2 = Question("Unicorns are:", ["mythological", "silver", "gold"])
    q2.query()
    q2.correct_answer()
    

which produces results such as:

    
    
    Frogs are: ['purple', 'red', 'green']
        Correct answer is green
    Unicorns are: ['gold', 'mythological', 'silver']
        Correct answer is mythological
    

Obviously this is just the sketch of a solution, input/output formatting and
presentation details would need to be worked out by you to your own
satisfaction.

