Quizbot Readthedocs Io en Latest
Quizbot Readthedocs Io en Latest
Quizbot Readthedocs Io en Latest
ducknrone
1 Quiz Foundation 3
1.1 1. Init a quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 2. Create a question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 3. Add a question to quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 4. Attempt to quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Question types 5
2.1 Multiple choice: QuestionChoice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Single choice: QuestionChoiceSingle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Yes or no : QuestionBool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Check number: QuestionNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Check string: QuestionString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Telegram bot 7
4 Module Documentation 11
4.1 Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3 Attempt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.4 Bot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.5 Create quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.6 Attempt quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.7 Edit quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Index 21
i
ii
QuizBot
QuizBot is a Telegram bot with which you can create and attempt quizzes. A quiz is a collection of possibly random
questions.
The processes and conversation of creating, attempting to, renaming, and removing existing quizzes can be shown as
automata-diagrams. Please take a look at the docs, specifically the part of the bot itself.
If you want to read more about the quiz foundation, take a look into Quiz Foundation. If you want to read more about
the question types, take a look into Question types.
CONTENTS: 1
QuizBot
2 CONTENTS:
CHAPTER
ONE
QUIZ FOUNDATION
With the Quiz Foundation you can. . . - . . . create Quizzes with quiz.quiz.py - . . . create Questions of different kinds
with quiz.question_factory.py - . . . attempt quizzes with quiz.attempt.py.
Lets get threw the process.
With the class Quiz in quiz.quiz.py, you create a new quiz by creating a new Quiz-object. You can specify an author by
entering the authors’ name by argument. Otherwise, the author is an empty string.
my_quiz = Quiz("my_name")
Before you can add a question to the quiz you have to create one.
You can create a new question by using one of the subclasses of Question in quiz.question_factory.py. You have to
pass two arguments by the creator: - the question itself as a string - the correct answer(s separated by a ‘,’ if it’s a
multiple-choice question) as a string.
Whatever kind of question you choose, the program checks if the entered answer is convertible to the wanted format.
In this case, you just want to ask for a string.
>>> my_quiz.add_question(my_question)
If we’d want to add more questions to the quiz, we would create a new question and add it. Otherwise, we could specify
if we want to print questions in random order (and more stuff ;). At the moment we don’t want to do more. But we
want to attempt it.
3
QuizBot
We can attempt to a quiz by passing it to the constructor of the Attempt class in quiz.attempt.py.
Now we can if it has a question left with has_next_question. In that case, we can ask for the question itself with
act_question. If we know the answer to the question, we pass it by input_answer as a string and call enter_answer to
enter it. You can check whether you were right or not by checking the return value of enter_answer.
>>> print(my_attempt.has_next_question())
true
>>> print(my_attempt.act_question)
"What's the best project?"
>>> act_question.input_answer("QuizBot")
>>> print(act_question.enter_answer())
true
>>> print(my_attempt.has_next_question())
false
Because we don’t have questions left, we can check the result of every question in my_attempt.user_points. That’s
it. . . it’s not rocket science ;)
TWO
QUESTION TYPES
You can use different kinds of questions in your quizzes. But you are free to add more by creating a subclass of Question.
Here are the types which already exist.
What is QuizBot?
1. A Telegram bot
2. A python application
3. A city
Answer: A Telegram bot, A python application
What is Quizbot?
1. A Telegram bot
2. A dish
3. A fish
Answer: A Telegram bot
5
QuizBot
THREE
TELEGRAM BOT
The telegram bot is using the quiz foundation and it has three main functions: - creating a quiz, - attempt a quiz, - edit
data at database.
Every one of them uses a ConversationHandler and their way to work is specified in: - bot.create_quiz.py, -
bot.attempt_quiz.py, - bot.edit_quiz.py.
The best way to show their way to work is by using an automata diagram. You can cancel the process during the creation
and attempt like in the renaming and removing process.
The rename- and remove-process takes place in bot.edit_quiz.py. Saving, loading, renaming and deleting a quiz works
with mongoDB
7
QuizBot
9
QuizBot
FOUR
MODULE DOCUMENTATION
4.1 Quiz
With this module, you can create quizzes with questions different kinds.
class quizbot.quiz.quiz.Quiz(author='')
Bases: object
An Instance of the class Quiz has a list of questions, which defines the Quiz. You can choose whether
• the order of the questions is random
• the result of the entered answer is shown after the question
• the result of the entered answer of every question is shown after the quiz
__init__(author='') → None
Initializes an instance of the class Quiz.
Parameters author – Author of the quiz
add_question(new_question: quizbot.quiz.question_factory.Question)
Add an instance of the class Question to the list of questions.
Parameters new_question – New question of the quiz.
get_questions()
Returns a copy of the list of questions.
Returns List of questions.
4.2 Questions
11
QuizBot
__init__(question, correct_answer)
Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as
an empty string.
Parameters
• question – Question of the question-instance as string.
• correct_answer – Correct answer of the question in (question specific) type.
Raises AssertionError – If the question or the correct answer is empty.
check_solution()
Checks the entered solution of the user with the correct answer.
Returns Boolean value whether the entered solution equals the correct answer.
Raises AssertionError – No solution was entered by the user yet.
enter_solution(answer)
Enters the answer by the user.
Parameters answer – Answer by the user as a string.
class quizbot.quiz.question_factory.QuestionBool(question, correct_answer)
Bases: quizbot.quiz.question_factory.Question
Subclass for questions with a boolean value as answer. Inherits by question.
__init__(question, correct_answer)
Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as
an empty string.
Parameters
• question – Question of the question-instance as string.
• correct_answer – Correct answer of the question as boolean value (True or False).
Raises AssertionError – If the question or the correct answer is not a boolean value.
check_solution()
Compares the entered answer by the user with the correct boolean value.
Returns Boolean value whether the entered value equals the correct value.
Raises AssertionError – If no solution was entered by the user yet.
enter_solution(answer)
Enters the users’ answer.
Parameters answer – Answer by the user as a string.
Raises AssertionError – If the entered answer isn’t “True” or “False”
class quizbot.quiz.question_factory.QuestionChoice(question, correct_answer)
Bases: quizbot.quiz.question_factory.Question
Subclass for questions with multiple possible and correct answers. Inherits by question.
__init__(question, correct_answer)
Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as
an empty string, the randomness as False and the list of possible answers as a list of correct answers.
Parameters
4.2. Questions 13
QuizBot
check_solution()
Compares the entered answer by the user with the correct number.
Returns Boolean value whether the entered number equals the correct number.
Raises AssertionError – If no solution was entered by the user yet.
enter_solution(answer)
Enters the answer by the user.
Parameters answer – Answer by the user as a string.
Raises ValueError – If answer is not an integer.
class quizbot.quiz.question_factory.QuestionString(question, correct_answer)
Bases: quizbot.quiz.question_factory.Question
Subclass for questions with a string as answer. Inherits by question.
check_solution()
Checks the entered answer of the user with the correct string.
Returns Boolean value whether the entered string equals the correct string.
Raises AssertionError – If no solution was entered by the user yet.
4.3 Attempt
4.4 Bot
4.4. Bot 15
QuizBot
Module with methods to rename and remove a quiz with a telegram bot
quizbot.bot.edit_quiz.cancel_edit(update, _)
Cancels the process of deletion or renaming.
quizbot.bot.edit_quiz.enter_name_remove(update, context)
Deltes a quiz after entering its’ name.
quizbot.bot.edit_quiz.enter_new_name(update, context)
After entering the new name of the quiz, it renames it.
quizbot.bot.edit_quiz.enter_old_name(update, context)
After entering the old quiz name, it asks for the new one.
quizbot.bot.edit_quiz.start_remove(update, _)
Start a process to remove a quiz.
quizbot.bot.edit_quiz.start_rename(update, _)
Starts a process to rename a quiz.
FIVE
• genindex
• modindex
• search
17
QuizBot
q
quizbot.bot.attempt_quiz, 16
quizbot.bot.bot, 15
quizbot.bot.create_quiz, 15
quizbot.bot.edit_quiz, 16
quizbot.quiz.attempt, 14
quizbot.quiz.question_factory, 11
quizbot.quiz.quiz, 11
19
QuizBot
Symbols 16
__init__() (quizbot.quiz.attempt.Attempt method), 14 enter_answer() (in module quizbot.bot.create_quiz), 15
__init__() (quizbot.quiz.question_factory.Question enter_answer() (quizbot.quiz.attempt.Attempt method),
method), 11 14
__init__() (quizbot.quiz.question_factory.QuestionBool enter_name_remove() (in module
method), 12 quizbot.bot.edit_quiz), 16
__init__() (quizbot.quiz.question_factory.QuestionChoiceenter_new_name() (in module quizbot.bot.edit_quiz),
method), 12 16
enter_old_name()
__init__() (quizbot.quiz.question_factory.QuestionChoiceSingle (in module quizbot.bot.edit_quiz),
method), 13 16
__init__() (quizbot.quiz.question_factory.QuestionNumber enter_possible_answer() (in module
method), 13 quizbot.bot.create_quiz), 15
__init__() (quizbot.quiz.quiz.Quiz method), 11 enter_question() (in module quizbot.bot.create_quiz),
15
A enter_quiz() (in module quizbot.bot.attempt_quiz), 16
enter_quiz_name() (in module
act_question() (quizbot.quiz.attempt.Attempt method),
quizbot.bot.create_quiz), 15
14
enter_randomness_question() (in module
add_possible_answer()
quizbot.bot.create_quiz), 15
(quizbot.quiz.question_factory.QuestionChoice
enter_randomness_quiz() (in module
method), 13
quizbot.bot.create_quiz), 15
add_question() (quizbot.quiz.quiz.Quiz method), 11
enter_result_after_question() (in module
ask_question() (in module quizbot.bot.attempt_quiz),
quizbot.bot.create_quiz), 15
16
enter_result_after_quiz() (in module
Attempt (class in quizbot.quiz.attempt), 14
quizbot.bot.create_quiz), 15
C enter_solution() (quizbot.quiz.question_factory.Question
method), 12
cancel() (in module quizbot.bot.attempt_quiz), 16
enter_solution() (quizbot.quiz.question_factory.QuestionBool
cancel() (in module quizbot.bot.create_quiz), 15
method), 12
cancel_edit() (in module quizbot.bot.edit_quiz), 16
enter_solution() (quizbot.quiz.question_factory.QuestionChoiceSingle
check_solution() (quizbot.quiz.question_factory.Question
method), 13
method), 12
enter_solution() (quizbot.quiz.question_factory.QuestionNumber
check_solution() (quizbot.quiz.question_factory.QuestionBool
method), 14
method), 12
enter_type() (in module quizbot.bot.create_quiz), 15
check_solution() (quizbot.quiz.question_factory.QuestionChoice
error() (in module quizbot.bot.bot), 15
method), 13
check_solution() (quizbot.quiz.question_factory.QuestionNumber
method), 13
G
get_questions() (quizbot.quiz.quiz.Quiz method), 11
check_solution() (quizbot.quiz.question_factory.QuestionString
method), 14
H
E has_next_question() (quizbot.quiz.attempt.Attempt
enter_answer() (in module quizbot.bot.attempt_quiz), method), 14
21
QuizBot
I
input_answer() (quizbot.quiz.attempt.Attempt method),
14
M
module
quizbot.bot.attempt_quiz, 16
quizbot.bot.bot, 15
quizbot.bot.create_quiz, 15
quizbot.bot.edit_quiz, 16
quizbot.quiz.attempt, 14
quizbot.quiz.question_factory, 11
quizbot.quiz.quiz, 11
P
print_help() (in module quizbot.bot.bot), 15
Q
Question (class in quizbot.quiz.question_factory), 11
QuestionBool (class in quizbot.quiz.question_factory),
12
QuestionChoice (class in
quizbot.quiz.question_factory), 12
QuestionChoiceSingle (class in
quizbot.quiz.question_factory), 13
QuestionNumber (class in
quizbot.quiz.question_factory), 13
QuestionString (class in
quizbot.quiz.question_factory), 14
Quiz (class in quizbot.quiz.quiz), 11
quizbot.bot.attempt_quiz
module, 16
quizbot.bot.bot
module, 15
quizbot.bot.create_quiz
module, 15
quizbot.bot.edit_quiz
module, 16
quizbot.quiz.attempt
module, 14
quizbot.quiz.question_factory
module, 11
quizbot.quiz.quiz
module, 11
S
setup_bot() (in module quizbot.bot.bot), 15
start() (in module quizbot.bot.attempt_quiz), 16
start() (in module quizbot.bot.create_quiz), 15
start_remove() (in module quizbot.bot.edit_quiz), 16
start_rename() (in module quizbot.bot.edit_quiz), 16
22 Index