Python小游戏和从文件读取

2024-04-26 20:53:56 发布

您现在位置:Python中文网/ 问答频道 /正文

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"

问题=? 答案=?在

我想让它检查我有多少问题,但我想从文本文件中添加问题和其他值。在

这就是我目前所掌握的,但是我真的很困惑如何从同一个文本文件中添加问题、答案、类别和分值。。在

文本文件示例琐事.txt公司名称:

^{pr2}$

Tags: 答案answerselfobjectinitresponsedefdescription
0条回答
网友
1楼 · 发布于 2024-04-26 20:53:56

分号分隔,即

Category:Question:Choice 1:Choice 2:Choice 3:Choice 4:etc

读入并传递给对象:

^{pr2}$

你知道有一个iterable列表,可以用来给问题赋值。这只是一种可能的解决办法。在

您还可以查看字典路径:

Creating a dictionary from a string

相关问题 更多 >