class Question(object):
def __init__(self, question, options, answer, description, points):
self.question = question
self.options = options
self.answer = answer
self.description = description
self.points = points
def ask():
response = None
while response not in ("1", "2", "3", "4"):
response = raw_input(self.question).lower()
if response == self.answer:
print "right"
else:
print "wrong"
问题=?答案=?
我希望它通过我的问题数量,但我想从文本文件中添加问题和其他值。
这就是我到目前为止所拥有的,但我真的很困惑如何从同一个文本文件中添加问题、答案、类别和点值..
文本文件示例 trivia.txt:
Category
Question
Choice 1
Choice 2
Choice 3
Choice 4
Answer (being a digit 1-4)
Description why it is that answer
Point Value