首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python :无法连接“str”和“builtin_function_or_method”对象

Python :无法连接“str”和“builtin_function_or_method”对象
EN

Stack Overflow用户
提问于 2016-07-20 22:59:39
回答 1查看 707关注 0票数 0

我目前正在用Python编写一个基于文本的冒险程序,作为学习练习。到目前为止,播放器可以自己命名,其值存储在字典键中。但是,当我试图允许玩家选择他们的种族时,我会得到以下错误:

无法连接“str”和“builtin_function_or_method”对象

我一遍又一遍地检查我的代码,似乎找不出出了什么问题。我对Python有点陌生,所以我认为它很简单,我正在忽略它。

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-20 23:00:43

您需要调用这个较低的方法,它是一个可调用的属性:

代码语言:javascript
复制
player_race = raw_input(">> ").lower()
#                                   ^^
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38492226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档