Python- How can I randomise questions that have an A,B,C,D

后端 未结 4 607
旧时难觅i
旧时难觅i 2020-12-22 13:40

My aim is to have it so it can randomise questions.

For example, the test starts and the first question could be question 8. The word Question is only

4条回答
  •  无人及你
    2020-12-22 14:12

    You could put answers in a list and call random.shuffle() on it:

    import random
    
    answers = [
        "Open Systematic Information",
        "Open Systems Interconnect",
        "Organised Stairway Interweb",
        "Open Safe Internet",
    ]
    random.shuffle(answers)
    
    for letter, answer in zip("ABCD", answers):
        print("{}- {}".format(letter, answer))
    

    Each time you run it, it may produce different output e.g.:

    A- Organised Stairway Interweb
    B- Open Systematic Information
    C- Open Safe Internet
    D- Open Systems Interconnect
    

提交回复
热议问题