我目前正在使用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()
答案 0 :(得分:0)
您需要调用较低的方法,它是可调用的属性:
player_race = raw_input(">> ").lower()
# ^^