目前,我正在用Python编写基于文本的冒险程序,作为学习练习。到目前为止,玩家可以自己命名,其值存储在字典键中。但是,当我尝试允许玩家选择种族时,出现以下错误:
无法连接“ str”和“ builtin_function_or_method”对象
我一次又一次地检查代码,似乎无法弄清楚出什么问题了。我是Python的新手,所以我认为这是我所忽略的简单事情。
player = {
"name": "",
"gender": "",
"race": "",
"class": "",
"HP": 10,
}
def error():
print "Error: Unknown Command"
print "You will have to forgive me, " + player['name'] + ". My eyesight isn't what it used to be. What are you, exactly?."
print "- A mighty HUMAN"
print "- A hardy DWARF"
print "- An ingenious GNOME "
print "- or an elegant ELF"
print "(Hint: If you would like to know more about each race, consult the manual, whatever that means)"
player_race = raw_input(">> ").lower
while race_confirm == False:
if player_race != "elf":
print "You say you're a " + player_race + ". Is that correct? Remember, you will be unable to change your race later. (Y/N)"
response = raw_input(">> ").lower()
else:
print "You say you're an " + player_race + ". Is that correct? Remember, you will be unable to change your race later. (Y/N)"
response = raw_input(">> ").lower()
if response == "y":
player_race = player['race']
print "It is nice to meet you, ", player['name'] + "the" + player['race'] + "."
race_confirm = True
elif response == "n":
print "Oh, I'm terribly sorry. I must have misheard you. What did you say you were again?"
player_name = raw_input(">> ")
else:
error()
您需要调用该较低的方法,这是一个可调用的属性:
player_race = raw_input(">> ").lower()
# ^^
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句