我目前正在用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()发布于 2016-07-20 23:00:43
您需要调用这个较低的方法,它是一个可调用的属性:
player_race = raw_input(">> ").lower()
# ^^https://stackoverflow.com/questions/38492226
复制相似问题