|
|
发表于 2020-4-26 10:06:25
|
显示全部楼层
本楼为最佳答案
本帖最后由 _2_ 于 2020-4-26 10:26 编辑
我给你重写了一个,你看看行不行:
- import random as r
- class ReciteWords:
- def __init__(self, **args):
- """
- You shoud input like English='Chinese'.
- For example, ReciteWords(my='我的', you='你的')
- """
- self.wordsDict = {**args}
- self.EnglishWords = list(self.wordsDict.keys())
- def start(self):
- """
- Start recite words.
- """
- used = []
- unused = self.EnglishWords
- wrong = []
- times = 0
- total_times = len(unused)
- isWrong = False
- while unused:
- a = r.choice(unused)
- if input("(%d / %d)请输入 %s 的意思:" % (times, total_times, a)) == self.wordsDict.get(a):
- print("恭喜你, 答对了!")
- used.append(unused.pop(unused.index(a)))
- times += 1
- continue
- else:
- print("正确答案是: %s" % self.wordsDict.get(a))
- used.append(unused.pop(unused.index(a)))
- wrong.append(used[-1])
- isWrong = True
- times += 1
- continue
- print("测试结束!")
- print("你本次累计练习 %d 题!" % total_times)
- if isWrong:
- print("你出现了一些错误")
- print("你出现的错误有: ", [i for i in wrong])
- print("继续努力!")
- input()
- return None
- if __name__ == "__main__":
- a = ReciteWords(robber="强盗",rob="抢劫",king="国王",act="扮演",reasonable="合理的",imaginative="富于想象的",imagination="想象力",reason="理由",able="有能力的",dub"配音",confused="疑惑",musical="乐团",music="音乐",amazing="惊奇",different="不同的",younger="较年轻的",young="年轻的",youngest="最年轻的",freshest="最新鲜的",fresher="比较新鲜的",fresh="新鲜的",sausage="腊肠",rest="休息")
- a.start()
复制代码 |
|