티스토리 뷰

main.py

from question_model import Question
from data import question_data
from quiz_brain import QuizBrain
question_bank = []
# for i in range(0,len(question_data)):
#     new_question = Question(question_data[i]["text"], question_data[i]["answer"])
#     question_bank.append(new_question)
#
# for list in question_data:
#     question = list["text"]
#     answer = list["answer"]
#     new_list = Question(question, answer)
#     question_bank.append(new_list)
for list in question_data:
    new_list = Question(list["text"], list["answer"])
    question_bank.append(new_list)
quiz = QuizBrain(question_bank)
quiz.next_question()

 

data.py

question_data = [
    {"text": "A slug's blood is green.", "answer": "True"},
    {"text": "The loudest animal is the African Elephant.", "answer": "False"},
    {"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"},
    {"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"},
    {"text": "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to "
             "eat.", "answer": "True"},
    {"text": "In London, UK, if you happen to die in the House of Parliament, "
             "you are entitled to a state funeral.", "answer": "False"},
    {"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"},
    {"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"},
    {"text": "Google was originally called 'Backrub'.", "answer": "True"},
    {"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"},
    {"text": "No piece of square dry paper can be folded in half more than 7 times.", "answer": "False"},
    {"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"}
]

 

question_model.py

class Question:
    def __init__(self, q_text, q_answer):
        self.text = q_text
        self.answer = q_answer

 

quiz_brain.py

class QuizBrain:
    def __init__(self,question_bank):
        self.question_number = 0
        self.question_list = question_bank
    def next_question(self):
        self.question_number += 1
        input(f"Q.{self.question_number}: {self.question_list[self.question_number-1].text} (True/False): ")
    # def next_question(self):
    #     current_question = self.question_list[self.question_number]
    #     self.question_number += 1
    #     input(f"Q.{self.question_number}: {current_question.text} (True/False): ")

'Test > Python(20220101~)' 카테고리의 다른 글

Days18. Import module (모듈)  (0) 2022.02.20
Days18. Turtle, GUI  (0) 2022.02.19
Days17.퀴즈 프로젝트2  (0) 2022.02.15
Days17. 퀴즈 프로젝트  (0) 2022.02.14
Days17.Method in Class  (0) 2022.02.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함