鱼C论坛

 找回密码
 立即注册
查看: 1638|回复: 8

[已解决]我想做个背单词的小程序,但二次答题那段有bug(望大神指点)

[复制链接]
发表于 2020-4-26 10:06:25 | 显示全部楼层    本楼为最佳答案   
本帖最后由 _2_ 于 2020-4-26 10:26 编辑

我给你重写了一个,你看看行不行:

  1. import random as r

  2. class ReciteWords:
  3.     def __init__(self, **args):
  4.         """
  5.         You shoud input like English='Chinese'.
  6.         For example, ReciteWords(my='我的', you='你的')
  7.         """
  8.         self.wordsDict = {**args}
  9.         self.EnglishWords = list(self.wordsDict.keys())

  10.     def start(self):
  11.         """
  12.         Start recite words.
  13.         """
  14.         used = []
  15.         unused = self.EnglishWords
  16.         wrong = []
  17.         times = 0
  18.         total_times = len(unused)
  19.         isWrong = False
  20.         while unused:
  21.             a = r.choice(unused)
  22.             if input("(%d / %d)请输入 %s 的意思:" % (times, total_times, a)) == self.wordsDict.get(a):
  23.                 print("恭喜你, 答对了!")
  24.                 used.append(unused.pop(unused.index(a)))
  25.                 times += 1
  26.                 continue
  27.             else:
  28.                 print("正确答案是: %s" % self.wordsDict.get(a))
  29.                 used.append(unused.pop(unused.index(a)))
  30.                 wrong.append(used[-1])
  31.                 isWrong = True
  32.                 times += 1
  33.                 continue

  34.         print("测试结束!")
  35.         print("你本次累计练习 %d 题!" % total_times)
  36.         if isWrong:
  37.             print("你出现了一些错误")
  38.             print("你出现的错误有: ", [i for i in wrong])
  39.             print("继续努力!")

  40.         input()

  41.         return None

  42. if __name__ == "__main__":
  43.     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="休息")
  44.     a.start()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-28 07:42:34 From FishC Mobile | 显示全部楼层
磊之茶 发表于 2020-4-27 22:04
谢谢

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-4-1 20:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表