dsci524_group13_quizit.utils¶
Classes¶
A class to represent and format the results of a quiz. |
Functions¶
|
Randomly selects a specified number of questions from the question bank. |
Prompts the user to input their answer. |
|
|
Print question and its options to the user or return a string containing the question and its options. |
|
Validates the user's input and ensures it matches the available options. |
|
Calculates the score for a question based on the user's input. |
|
Saves the quiz score and time taken to finish the quiz to a text file. |
|
Logs questions along with user's input based on the specified type (all, correct, or incorrect). |
Module Contents¶
- dsci524_group13_quizit.utils.select_questions(mcq, n)[source]¶
Randomly selects a specified number of questions from the question bank.
- dsci524_group13_quizit.utils.print_question(question, iter, print_q=True)[source]¶
Print question and its options to the user or return a string containing the question and its options.
- dsci524_group13_quizit.utils.input_check(user_input, n_options, count)[source]¶
Validates the user’s input and ensures it matches the available options.
- dsci524_group13_quizit.utils.mcq_score(options_dict, question_df, user_input)[source]¶
Calculates the score for a question based on the user’s input.
- dsci524_group13_quizit.utils.score_log(pct_score, time_used, question_type, save_score: bool, dir_name=None)[source]¶
Saves the quiz score and time taken to finish the quiz to a text file.
- dsci524_group13_quizit.utils.question_log(type, quiz, question_type: string, dir_name=None)[source]¶
Logs questions along with user’s input based on the specified type (all, correct, or incorrect).
- class dsci524_group13_quizit.utils.QuizResult(time_used, score, question_summary, question_type)[source]¶
A class to represent and format the results of a quiz.
- time_used¶
The total time (in seconds) taken to complete the quiz.
- Type:
int
- score¶
The percentage score achieved in the quiz.
- Type:
float
- question_summary¶
A pandas DataFrame containing question details, including ‘question’, ‘response’, ‘answers’, and ‘explanations’.
- Type:
DataFrame
- question_type¶
The type of questions in the quiz, e.g., ‘mcq’ (multiple-choice) or ‘shrtq’ (short-answer).
- Type:
str
- __repr__()[source]¶
Provides a formatted string representation of the quiz results, iterating through each question in the summary, displaying the question, user’s response, correct answer, explanation, and overall quiz stats.
Example
>>> from pandas import DataFrame >>> summary = DataFrame({ ... 'question': ["What is 2+2?", "What is the capital of France?"], ... 'response': ["4", "Paris"], ... 'answers': ["4", "Paris"], ... 'explanations': ["Basic math.", "France's capital is Paris."] ... }) >>> result = QuizResult(time_used=120, score=100, question_summary=summary, question_type='mcq') >>> print(result)
- time_used¶
- score¶
- question_summary¶
- question_type¶