Search code examples
pythoncommand-linetext-based

Python error: cannot concatenate 'str' and 'builtin_function_or_method' objects


I am currently in the process of programming a text-based adventure in Python as a learning exercise. So far, the player can name themselves, the value of which is stored in a dictionary key. However, when I attempt to allow the player to choose their race, I get the following error:

cannot concatenate 'str' and 'builtin_function_or_method' objects

I have gone over my code time and time again and can't seem to figure out what's wrong. I'm somewhat new to Python, so I assume it's something simple I'm overlooking.

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()

Solution

  • You need to call that lower method, it's a callable attribute:

    player_race = raw_input(">> ").lower()
    #                                   ^^