|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想做个背单词的小程序,但二次答题那段有bug(望大神指点迷津 )
- import os
- import time as g
- dan_ci=[]
- fan_yi=[]
- z1=0
- def jing_du_tiao(a):
- global z1
- os.system('cls')
- z1+=100/a
- print(str(int(z1+0.5))+'%')
- def jia(a,b):
- global dan_ci,fan_yi
- dan_ci.append(b)
- fan_yi.append(a)
- jing_du_tiao(23)
- os.system('color 5F')
- print('0%')
- jia('强盗','robber')
- jia('抢劫','rob')
- jia('国王','king')
- jia('扮演,行动','act')
- jia('合理的','reasonable')
- jia('富于想象的','imaginative')
- jia('想象力','imagination')
- jia('理由','reason')
- jia('有能力的','able')
- jia('配音,配乐','dub')
- jia('疑惑','confused')
- jia('乐团','musical')
- jia('音乐','music')
- jia('惊奇,太好了','amazing')
- jia('不同的','different')
- jia('较年轻的','younger')
- jia('年轻的','young')
- jia('最年轻的','youngest')
- jia('最新鲜的','freshest')
- jia('比较新鲜的','fresher')
- jia('新鲜的','fresh')
- jia('腊肠','sausage')
- jia('休息','rest')
- os.system('color 5F')
- cuo_wu=[]
- for i in range(len(dan_ci)):
- os.system('cls')
- da_an=input(fan_yi[i]+':')
- if da_an != dan_ci[i]:
- cuo_wu.append(dan_ci[i])
- os.system('cls')
- if len(cuo_wu) > 0:
- os.system('color 67')
- print('你错了:',end='')
- for i in cuo_wu:
- print(i,end='、')
- g.sleep(len(cuo_wu)*5)
- while len(cuo_wu) > 0:#二次答题
- new_cuo_wu=[]
- os.system('color 5F')
- for i in cuo_wu:
- os.system('cls')
- da_an=input(fan_yi[dan_ci.index(i)]+':')#中英转换
- if da_an != i:
- new_cuo_wu.append(i)
- if len(new_cuo_wu) < 1:
- break
- else:
- cuo_wu=new_cuo_wu#避免无法删除对的
- os.system('color 67')
- print('你错了:',end='')
- for i in cuo_wu:
- print(i,end='、')
- g.sleep(10)
- os.system('cls')
- os.system('cls')
- os.system('color EC')
- print('你终于就把单词背下来了。')
- else:
- os.system('color EC')
- print('你一次就把单词背下来了,真棒!')
复制代码
这是源代码。
本帖最后由 _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()
复制代码
|
|