Share your repls and programming experiences

← Back to all posts
Quiz creator for Python (v1)
DarshanRajpara1 (13)

This is a Python module that I made which allows you to create a quiz, if you have any suggestions, let me know.

How to get it working

To use this module, create a file called, and copy the code below.

class Question:
  def __init__(self, value, a1, a2, a3, a4, cor):
    import random

    self.value = value
    self.answers = ['', a1, a2, a3, a4]
    self.correct = False
    if cor == 'random' or 'rand':
      self.cor = random.randrange(0,100) % 4 + 1
      self.cor = cor
  def ask(self):
    guess = int(input())
    if guess == self.cor:
      return True
      return False

Then, at the start of your main file type:

import quiz

Using it

To create a new question, use this code:

question = Question('question', 'answer 1', 'answer 2', 'answer 3', 'answer4', correctanswer)

The correctanswer value can also be set to 'rand' if you want a random answer to be correct.

To actually ask a question just type


The ask() function will return true if the user answers correctly, and false if they answer incorrectly.
Below is a simple history quiz.