很明显我做错了什么。我是一个新的 python/noob 编码器,所以对你们中的许多人来说可能很明显,但我不知道该怎么做。
class hero():
"""Lets do some heros shit"""
def __init__(self, name="Jimmy", prof="Warrior", weapon="Sword"):
"""Constructor for hero"""
self.name = name
self.prof = prof
self.weapon = weapon
self.herodict = {
"Name": self.name,
"Class": self.prof,
"Weapon": self.weapon
}
self.herotext = {
"Welcome": "Greetings, hero. What is thine name? ",
"AskClass": "A fine name %s. What is your class? " % self.herodict['Name'],
}
def thingy(self, textkey, herokey):
n = raw_input(self.herotext[textkey])
self.herodict[herokey] = n
if self.herodict[herokey] != "":
print self.herodict[herokey]
else:
self.herodict[herokey] = self.name
print self.herodict[herokey]
def setHeroName(self):
self.thingy("Welcome", 'Name')
def setHeroClass(self):
self.thingy("AskClass", 'Class')
所以基本上你运行它,它会设置一堆默认值。它会询问一个名字,然后你给它用户输入,然后它将 Name 键设置为你输入的新值。他们假设采用新的键:值或名称:(用户输入)并在下一个小句子中使用它。但相反,它返回并使用默认值'jimmy'。
我需要做什么?