Getting Started

To get started with your quiz, create an instance of the Quizit class.

from dsci524_group13_quizit import Quizit

quiz = Quizit()

The cell above creates an instance of the Quizit object, which allows you to load questions, take quizzes, and view results.

Question Types

The dsci524_group13_quizit package currently supports two types of questions:

  • MULTIPLE_CHOICE: Questions with multiple options where one or more can be correct.

  • SHORT_ANSWER: Questions that require a short text answer.

from dsci524_group13_quizit import QuestionType

To access a specific question type you can use the QuestionType class. Below is an example of accessing a multiple-choice question type:

print(QuestionType.MULTIPLE_CHOICE)
QuestionType.MULTIPLE_CHOICE

Or you can access a short-answer question type:

print(QuestionType.SHORT_ANSWER)
QuestionType.SHORT_ANSWER

Loading Questions

You can load questions into your quiz in two ways:

  • From a DataFrame

  • From a file

Important Notes

  • You can only load from one of the two options at a time - you cannot simultaneously load from a file and a DataFrame.

  • You can only load one set of questions for each question type at once. Loading multiple question sets for a question type will store only the most recent question set. For example, if you load three sets of short-answer questions, only the third set will be stored and can be taken as a quiz.

Load Questions From a File

Loading Multiple-Choice Questions

Let’s start by loading multiple-choice questions from a file. You need to specify the file path, question type, and optionally, a delimiter to split the answers and options.

mcq_file_path = "../tests/test_data/multiple_choice.csv"
mc_questions = quiz.load_questions(input_file=mcq_file_path, question_type=QuestionType.MULTIPLE_CHOICE, delimiter=";")

The function loads the questions from the specified file, splits the options and answers based on the delimiter, and returns the questions as a DataFrame. Let’s take a look at the first three questions:

mc_questions.head(3)
question options answers explanations
0 What is the capital of France? [Paris, London, Berlin, Madrid] [Paris] Paris is the capital and most populous city of...
1 Which planet is known as the Red Planet? [Earth, Mars, Jupiter, Saturn] [Mars] Mars is often called the 'Red Planet' because ...
2 What is the largest ocean on Earth? [Atlantic Ocean, Indian Ocean, Arctic Ocean, P... [Pacific Ocean] The Pacific Ocean is the largest and deepest o...

The question contains four columns, which is the expected format of the input type: The question contains 4 columns which is the expected format of the input type

  1. question: the quiz question you want to take

  2. options: the different options specified for the particular question, these could be one or more options

  3. answers: one or more acceptable answers for the specific question

  4. explanations: an explanation for the answer(s) chosen

Loading Short Answer Questions

You can also load short answer questions from a file. You need to specify the file path and question type(the question type should be SHORT_ANSWER if you want to load short answer questions).

shrtq_file_path = "../tests/test_data/short_answer.csv"
shrtq_questions = quiz.load_questions(input_file=shrtq_file_path, question_type=QuestionType.SHORT_ANSWER)

The function loads the questions from the specified file and returns the questions as a DataFrame. Let’s take a look at the first three short answer questions:

shrtq_questions.head(3)
question answers explanations
0 What continent has the largest population Asia Asia is the most populous continent with over ...
1 What is the capital of France Paris Paris is the capital and most populous city of...
2 What is the largest planet in our solar system Jupiter Jupiter is the largest planet in our solar sys...

Load Questions From a DataFrame

You can also load questions directly from a DataFrame. This is useful if you already have your questions in a DataFrame format.

The data frame should be a pandas data frame so start off by importing the pandas package

import pandas as pd

Loading Multiple Choice Questions

Create the question dataframe with the expected format below. I should have 4 columns in the order specified below

  1. question: the quiz question you want to take

  2. options: the different options specified for the particular question, these could be one or more options in a list data type format

  3. answers: one or more acceptable answers for the specific question also expected in a list data type format

  4. explanations: an explanation for the answer(s) chosen

mcq_data = {
    'question': ['What is the capital of France?', 'What is 2 + 2?'],
    'options': [["Paris", "London", "Berlin", "Madrid"]	, ['4']],
    'answers': [["Paris"]	, ['4']],
    'explanations': ['The capital of France is Paris.', '2 + 2 equals 4.']
}
mcq_df = pd.DataFrame(mcq_data)

Below you can load the questions from the dataframe created above

df_mc_questions = quiz.load_questions(questions=mcq_df, question_type=QuestionType.MULTIPLE_CHOICE)

The function loads in the multiple choice questions, sets the internal quizit object and returns a copy of the questions

df_mc_questions
question options answers explanations
0 What is the capital of France? [Paris, London, Berlin, Madrid] [Paris] The capital of France is Paris.
1 What is 2 + 2? [4] [4] 2 + 2 equals 4.

Loading Short Answer Questions

Create the question dataframe with the expected format below. I should have 3 columns in the order specified below

  1. question: the quiz question you want to take

  2. answers: one or more acceptable answers for the specific question also expected

  3. explanations: an explanation for the answer(s) chosen

shrtq_data = {
    'question': ['What continent has the largest population', 'What is the capital of France'],
    'answers': ['Asia', 'Paris'],
    'explanations': ['TAsia is the most populous continent with over', 'Paris is the capital and most populous city of']
}
shrtq_df = pd.DataFrame(shrtq_data)

Below you can load the short answer questions from the dataframe created above

shrtq_df_questions = quiz.load_questions(questions=shrtq_df, question_type=QuestionType.SHORT_ANSWER)

The function loads the questions from the DataFrame and returns them. Let’s view the returned questions:

shrtq_df_questions.head()
question answers explanations
0 What continent has the largest population Asia TAsia is the most populous continent with over
1 What is the capital of France Paris Paris is the capital and most populous city of

Taking A Quiz

Once you have loaded your questions, you can take a quiz. The Quizit class provides methods to take both multiple-choice and short-answer quizzes.

Take a Multiple-Choice Quiz

Take a Short-Answer Quiz