Beispiel #1
0
def main():
    print(logo)
    question_bank = []
    num_of_questions = len(question_data)

    for i in range(num_of_questions):
        question_bank.append(
            Question(question_data[i]["text"], question_data[i]["answer"]))

    Quizzer = QuizBrain(question_bank)
    questions = random.sample(question_bank, Quizzer.no_of_questions_to_ask)

    print(f"I found {num_of_questions} questions.")
    print(
        f"I have chosen {Quizzer.no_of_questions_to_ask} random questions\n" \
        f"to ask you. Good luck :)\n" )

    while questions:
        if Quizzer.question(questions.pop()):
            Quizzer.score += 1
            print(f'Correct, you earn a point [{Quizzer.score}/{Quizzer.no_of_questions_to_ask}]\n')

        else:
            print('That is incorrect\n')

    print(f"final score: {Quizzer.score}/{Quizzer.no_of_questions_to_ask}")
Beispiel #2
0
def main():

    response = requests.get("https://opentdb.com/api.php?amount=50&type=boolean")
    openTriviaDB = json.loads(response.text)

    print("\n", ascii_art, "\nWelcome to The Quiz!")

    num_questions = int(input("How many questions do you want? (0-50) "))

    question_bank = [Question(openTriviaDB["results"][i]["question"], openTriviaDB["results"][i]["correct_answer"]) for i in range(num_questions)]
    quiz = QuizBrain(question_bank)

    print()

    while quiz.still_has_questions():
        quiz.next_question()

    print(f"You've completed the quiz!\n Your final score was {quiz.score}/{len(question_bank)}")

    option = input("Do you want to play again? y/n ")

    if option == 'y':
        main()
    else:
        exit()
Beispiel #3
0
def qdata_list_to_qobj_list(question_data):
    question_bank = []

    for question in question_data:
        question_text = question["question"]
        question_answer = question["correct_answer"]
        new_question = Question(question_text, question_answer)
        question_bank.append(new_question)

    return question_bank
Beispiel #4
0
    def ques_gen(self):
        question_data = GenerateData().question_data
        self.question_bank = []
        for question in question_data:
            question_text = question["question"]
            question_answer = question["correct_answer"]
            new_question = Question(question_text, question_answer)
            self.question_bank.append(new_question)

        self.question_list = self.question_bank
def question_bank_creation(data):
    question_bank = []
    for question in data:
        question_text = question["question"]
        question_answer = question["correct_answer"]

        new_question = Question(q_text=question_text, q_answer=question_answer)
        question_bank.append(new_question)

    return question_bank
Beispiel #6
0
def quiz():
    question_bank = []
    for item in question_data:
        new_question = Question(item['text'], item['answer'])
        question_bank.append(new_question)

    quiz_brain = QuizBrain(question_bank)
    while quiz_brain.still_has_questions():
        quiz_brain.next_question()

    quiz_brain.end_game_message()
Beispiel #7
0
    def _get_questions(self):

        questions = []
        question_data = data.get_questions()
        for question in question_data:
            question_text = question["question"]
            question_answer = question["correct_answer"]
            new_question = Question(question_text, question_answer)
            questions.append(new_question)

        return questions
Beispiel #8
0
def populate_bank():
    # Changed for loop to loop TriviaDB
    for i in open_trivia_db:
        # q = i["text"]
        # Modified for TriviaDB
        q = i["question"]
        # a = i["answer"]
        # Modified for TriviaDB
        a = i["correct_answer"]
        question = Question(q, a)
        question_bank.append(question)
Beispiel #9
0
def main():
    question_bank = []
    for question in question_data:
        question_text = question["question"]
        question_answer = question["correct_answer"]
        new_question = Question(question_text, question_answer)
        question_bank.append(new_question)

    quiz = QuizBrain(question_bank)
    quiz_ui = QuizInterface(quiz)

    print("You've completed the quiz")
    print(f"Your final score was: {quiz.score}/{quiz.question_number}")
Beispiel #10
0
def main():
    question_bank = []
    for elem in question_data:
        question_bank.append(Question(elem["question"],
                                      elem["correct_answer"]))

    quiz = QuizBrain(question_bank)

    while quiz.still_has_questions():
        quiz.next_question()

    print("You've completed the quiz")
    print(f"Your final score was: {quiz.score}/{quiz.question_number}.")
Beispiel #11
0
def main():
    question_bank = []
    for qa in question_data:
        question_bank.append(Question(qa['question'], qa['correct_answer']))

    shuffle(question_bank)

    qb = QuizBrain(question_bank)
    while qb.still_has_question() and qb.alive:
        qb.next_question()
    if qb.alive:
        print(
            f"Congratulations, you have completed the quiz with a score of {qb.score}"
        )
Beispiel #12
0
def construct_questions():
    response = requests.get(url="https://opentdb.com/api.php",
                            params=parameter)
    response.raise_for_status()
    data = response.json()
    question_data = data["results"]

    question_bank = []
    for question in question_data:
        question_text = question["question"]
        question_answer = question["correct_answer"]
        new_question = Question(question_text, question_answer)
        question_bank.append(new_question)

    return question_bank
Beispiel #13
0
def main():
    """
    Creates instances of the classes to implement the quiz
    :return: nothing
    """
    question_bank = []
    for question in question_data:
        new_quest = Question(question['question'], question['correct_answer'])
        question_bank.append(new_quest)

    quiz = QuizBrain(question_bank)
    while quiz.still_has_questions():
        quiz.next_question()

    print('You have completed the quiz')
    print(f'The final score is: {quiz.score}/{len(quiz.question_list)}')
    def __init__(self, q_list):
        """Generate random question list from Open Trivia API"""
        # Set initial class variables
        self.question_number = 0
        self.score = 0
        self.question_list = []

        # Ask user for desired question set up and format
        diff = input("Pick a difficulty (hard/medium/easy):").lower()
        if diff != "hard" and diff != "medium":
            diff = "easy"
        try:
            q_count = int(input("How many questions do you want? (1-10):"))
            if q_count > 10 or q_count < 2:
                q_count = 10
        except ValueError:
            q_count = 3

        # Use JSON API to pull random questions from internet
        self.json_bank = (requests.get("https://opentdb.com/api.php?amount=" +
                                       str(q_count) +
                                       "&category=18&difficulty=" + diff +
                                       "&type=multiple"))
        if self.json_bank.status_code != 200:
            print(
                "ERROR: Couldn't establish an internet connection to remote server. "
                "Using default questions bank instead")
            self.question_list = q_list
        else:
            # Get api string
            api_bank = json.loads(self.json_bank.text)['results']
            for i in range(len(api_bank)):
                d_question = dict(api_bank[i])
                i_question = Question(d_question["question"],
                                      d_question["correct_answer"],
                                      d_question["incorrect_answers"])
                self.question_list.append(i_question)
Beispiel #15
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain
from ui import QuizInterface

question_bank = []

for question in question_data:
    question_text = question["question"]
    question_answer = question["correct_answer"]
    new_question = Question(question_text, question_answer)
    question_bank.append(new_question)

quiz = QuizBrain(question_bank)
quiz_ui = QuizInterface(quiz)
Beispiel #16
0
# Quizzler

import data
from question_model import Question
from quiz_brain import QuizBrain
from ui import QuizInterface

question_bank = []
# fill up the question bank list with Question objects
for dic in data.load_data():
    question_bank.append(Question(dic["question"], dic["correct_answer"]))

# initialize the quiz brain
qb = QuizBrain(question_bank)
# initialize the GUI
qi = QuizInterface(qb)
Beispiel #17
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []
for i in question_data:
    question_bank.append(Question(i["question"], i["correct_answer"]))

quiz = QuizBrain(question_bank)


while quiz.still_has_questions():
    quiz.next_question()


print(f"You've completed the quiz, Your final score was: {quiz.score}/{quiz.question_number}")
Beispiel #18
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain
from ui import UInterface

question_bank = []

for el in question_data:
    question_bank.append(Question(el))

quiz = QuizBrain(question_bank)

# while quiz.still_has_questions():
#     quiz.next_question()

ui = UInterface("Quizzzy", quiz)

print("You have completed the quiz!")
print(f"Your final score is {quiz.score}/{quiz.question_number}")
Beispiel #19
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []
for question in question_data:
    text = question["text"]
    answer = question["answer"]
    new_question = Question(text, answer)
    question_bank.append(new_question)

quiz = QuizBrain(question_bank)
while quiz.still_has_questions():
    quiz.next_question()

print("You've completed the quiz.")
print(f"Your final score was: {quiz.score}/{len(question_bank)}")
Beispiel #20
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []
for question in question_data:
    new_question = Question(question["text"], question["answer"])
    question_bank.append(new_question)

quiz_brain = QuizBrain(question_bank)

while quiz_brain.still_has_questions():
    quiz_brain.next_question()
Beispiel #21
0
from data import question_data
from question_model import Question
from quiz_brain import QuizzBrain

question_bank = []
for question in question_data:
    q_text = question["question"]
    q_answer = question["correct_answer"]
    new_question = Question(q_text=q_text, q_answer=q_answer)
    question_bank.append(new_question)

quiz = QuizzBrain(question_bank)

while quiz.still_has_questions():
    quiz.next_question()
print("You have completed the Quiz!")
print(f"Your final score was: {quiz.score}/{quiz.q_number}")
Beispiel #22
0
from question_model import Question
from qg_data import question_data, questions_db
from quiz_brain import QuizBrain

question_bank = []
for _ in questions_db:
    question_ans = Question(_['text'], _['answer'])
    question_bank.append(question_ans)

quiz = QuizBrain(question_bank)

while quiz.still_has_questions():
    quiz.next_question()

print("\n")
print("You've completed the quiz.")
print(f"Your final scoree is {quiz.score}/{quiz.q_num}")
Beispiel #23
0
from question_model import Question
from quiz_brain import QuizBrain
from data import question_data

questions_bank = []
for question in question_data:
    questions_bank.append(Question(question["text"], question["answer"]))

quiz = QuizBrain(questions_bank)

while not quiz.all_questions_asked():
    quiz.next_question()

quiz.show_final_score()
Beispiel #24
0
from data import question_data
from question_model import Question
from quiz_brain import QuizBrain

question_bank = []

for item in question_data:
    question_bank.append(Question(item['text'], item['answer']))

quiz = QuizBrain(question_bank)

while quiz.still_has_question():
    quiz.next_question()

print("You've finished the quiz.")
print(f"Your final score is {quiz.score} / {quiz.question_number}")
Beispiel #25
0
# TODO 2. create question bank list contains questions objects initiated by question data
# write a for loop to iterate over the question_data
# create a Question object from each entry in question_data
# append each Question object to the question_bank
# TODO 8. print a complete message and the user's final score
# TODO 9. get new questions from Trivia
# change the name of the keys to get the correct data

from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []

for question in question_data:
    question_bank.append(
        Question(question["question"], question["correct_answer"]))

quiz_brain = QuizBrain(question_bank)
while quiz_brain.still_has_questions():
    quiz_brain.next_question()
else:
    print("You've completed the quiz!")
    print(
        f"Your final score was {quiz_brain.score}/{quiz_brain.question_number}."
    )
Beispiel #26
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []

# for i in range(len(question_data)):
#     question_bank.append(
#         Question(text=question_data[i]["text"], answer=question_data[i]["answer"])
#     )

for question in question_data:
    question_text = question["text"]
    question_answer = question["answer"]
    new_question = Question(text=question_text, answer=question_answer)
    question_bank.append(new_question)

quiz = QuizBrain(question_bank)

while quiz.still_has_question():
    quiz.next_question()

print("You've completed the quiz")
print(f"You're final score was: {quiz.score}/{len(question_data)}")
Beispiel #27
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []
for i in question_data:
    question_bank.append(Question(i.get('question'), i.get('correct_answer')))

brain = QuizBrain(question_bank)
while brain.still_has_questions():
    brain.next_question()

print("Game Over!")
print(f"Your Final Score: {brain.score}/{len(question_bank)}")

Beispiel #28
0
"""
    TRUE-FALSE QUIZ APP
"""

from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

# questions bank
question_bank = []
for dictionary in question_data:
    question = Question(dictionary["question"], dictionary["correct_answer"])
    question_bank.append(question)

quiz = QuizBrain(question_bank)

while quiz.still_has_question():
    quiz.next_question()

print(f"You've completed the quiz!\nYour final score is {quiz.score} out of {quiz.question_number}")
Beispiel #29
0
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain

question_bank = []

for i in question_data:
    new_question = Question(i['question'], i['correct_answer'])
    question_bank.append(new_question)

quiz = QuizBrain(question_bank)

while quiz.still_has_questions():
    quiz.next_question()

print("You have completed the quiz")
print(f"Your final score was: {quiz.score}/{len(quiz.question_list)}")
Beispiel #30
0
def make_instance5():
    for question in question_data5:  
        text = question["text"]
        answer = question["answer"]
        question_bank.append(Question(text, answer))