现在我的抽认卡游戏使用的是prepvocab()
方法
每次我添加一个新的一周的术语和翻译,我都会在可用词典列表中添加另一个元素。我可以肯定这不是一件好事。你知道吗
class Vocab(object):
def __init__(self):
vocab = {}
self.new_vocab = vocab
self.prepvocab()
def prepvocab(self):
week01 = {"term":"translation"} #and many more...
week01d = "Simple Latvian words"
week02 = {"term":"translation"}
week02d = "Simple Latvian colors"
week03 = {"I need to add this":"to self.selvocab below"}
week03d = "Body parts"
self.selvocab = [week01, week02] #, week03, weekn]
self.descs = [week01d, week02d] #, week03, weekn]
Vocab.selvocab(self)
def selvocab(self):
"""I like this because as long as I maintain self.selvocab,
the for loop cycles through the options just fine"""
for x in range(self.selvocab):
YN = input("Would you like to add week " \
+ repr(x + 1) + " vocab? (y or n) \n" \
"Description: " + self.descs[x] + " ").lower()
if YN in "yes":
self.new_vocab.update(self.selvocab[x])
self.makevocab()
我可以肯定地看到,这将是一个痛苦的20+是不是的问题。我现在正在读咒语,并且正在考虑一次打印所有的描述,让用户选择他们想学习的所有内容。你知道吗
如何更好地维护代码的这一部分?有没有人有一个根本性的改革不是那么…程序性的?你知道吗
你应该把你的钱存起来术语:翻译对以及文本文件中的描述。然后,您的程序应该解析文本文件并发现所有可用的课程。这将允许您扩展可用的课程集,而无需编辑任何代码。你知道吗
对于课程的选择,编写一个
print_lesson_choices
函数,向用户显示可用的课程和描述,然后在选择课程时询问用户的输入。与其每节课都问他们一个问题,为什么不做如下提示:Pickling objects into a database意味着创建一个界面来修改前端的每周课程需要一些努力,但这是值得的。你知道吗
相关问题 更多 >
编程相关推荐