Python TypeError:参数类型为';功能';这是不可容忍的

Python TypeError:参数类型为';功能';这是不可容忍的,python,recursion,iterable,Python,Recursion,Iterable,错误: 我想我得到了这个错误,因为它是递归函数,但我在整个游戏中都使用了它们,它们一直工作到我添加了try\u() 以下是代码的其余部分,以防有所帮助: def try_again(): print "Would you like to try again?" user_input = uput if "y" in user_input or "yes" in user_input: start() elif "n" in user_input o

错误:

我想我得到了这个错误,因为它是递归函数,但我在整个游戏中都使用了它们,它们一直工作到我添加了try\u()

以下是代码的其余部分,以防有所帮助:

def try_again():
    print "Would you like to try again?"
    user_input = uput
    if "y" in user_input or "yes" in user_input:
        start()
    elif "n" in user_input or "no" in user_input:
        sys.exit()
    else:
        try_again()
#我为练习Python技能而制作的角色扮演游戏!
导入系统
def uput():#获取用户输入并使其全部小写
返回原始输入(“>”).lower()
def start():#开始游戏
打印“您所在的房间有左右两扇门。”
打印“您选择哪个?”
用户输入=uput()
如果用户输入=“左”:
打印“你打开门…”
拉瓦皮特()
elif user_input==“右”:
打印“你打开门…”
巨人()
其他:
打印“重试”。+“\n”*3
开始()
def lavapit():
在瓦尔卡诺的边缘印上“你的名字”
山区(10)
打印“一步走错,你就掉进火山!”
打印“您可以沿着边缘走到另一边,然后沿着路径走到底部”
打印“或返回房间!”
用户输入=uput()
如果用户输入中的“行走”或用户输入中的“沿着”或用户输入中的“边缘”:
打印“你绊倒了。”
打印“然后掉入熔岩!”
死亡()
elif用户输入中的“返回”或用户输入中的“门”或用户输入中的“返回”:
开始()
其他:
打印“重试”。+“\n”*3
拉瓦皮特()
def giant():
打印“你进入一个发霉的黑暗房间。”
打印“天花板很高”
打印“然后你听到……沉重的呼吸。”
打印“你是慢慢地、安静地向右走还是向左走?”
右=0
左=0
而权利3:
打印“你在墙上碰到一个巨大老鼠大小的黑洞。”
打印“您输入了吗?”
洞()
其他:
打印“重试”。+“\n”*3
巨人()
def dead():
打印“-”*30
打印“对不起,你松了!”
再试一次
定义孔():
用户输入=uput()
如果用户输入中的“是”或用户输入中的“y”:
打印“祝贺你!你什么都没赢!”
再试一次
如果用户输入中的“否”或用户输入中的“n”:
返回
其他:
洞()
def重试()
打印“您想再试一次吗?”
用户输入=uput
如果用户输入中的“y”或用户输入中的“是”:
开始()
如果用户输入中为“n”,或用户输入中为“否”:
sys.exit()
其他:
再试一次
def山(x):
i=2
当x>0时:
打印“*x+”@“*i
x-=1
i+=2
开始()

问题在于,在函数体的第二行中,
请重试
您没有调用
uput
,而是将其分配给
用户输入
。您忘记了括号,如果将其更改为:

    # Role Playing Game I made to practice my Python skills!
import sys

def uput(): # get user input and make it all lowercase
    return raw_input("> ").lower()

def start(): #Starts the game
    print "You are in room with a left and right door."
    print "Which do you choose?"
    user_input = uput()
    if user_input == "left":
       print "You open the door..."
       lavapit() 
    elif user_input == "right":
        print "You open the door..."
        giant()
    else:
        print "Try again." + "\n" * 3
        start()

def lavapit():
    print "Your on the edge of valcano."
    mountain(10)
    print "One wrong step and you fall into the volcano!"
    print "You can walk along the edge to the other side and take the path down to the base"
    print "Or return to the room!"
    user_input = uput()
    if "walk" in user_input or "along" in user_input or "edge" in user_input:
       print "You stumble."
       print "And fall off into the lava!" 
       dead()
    elif "return" in user_input or "door" in user_input or "go back" in user_input:
        start()
    else:
        print "Try again." + "\n" * 3
        lavapit()

def giant():
    print "You enter a dark musty room."
    print "With very high ceilings."
    print "Then you hear... heavy breathing."
    print "Do you walk slowly and quitely to your right or left."

    right = 0
    left = 0
    while right <= 4 or left <= 5:
        user_input = uput()
        if "right" in user_input and right < 3:
            print "You edge slowly to the right."
            right += 1
            left -= 1
        elif "left" in user_input and left < 4:
            print "You edge closer to the left."
            right -= 1
            left += 1
        elif "right" in user_input and right > 2:
            print "You bump into the giant and get eaten alive."
            print "The giant says, 'Yum'."
            dead()
        elif "left" in user_input and left > 3:
            print "You reach a dark hole in the wall the size of giant mouse."
            print "Do you enter it?"
            hole()
        else:
            print "Try again." + "\n" * 3
            giant()
def dead():
    print "-" * 30
    print "Sorry you loose!"
    try_again()     

def hole():
    user_input = uput()
    if "yes" in user_input or "y" in user_input:
        print "Congratulations! You won nothing!"
        try_again()
    elif "no" in user_input or "n" in user_input:
        return
    else:
        hole()

def try_again():
    print "Would you like to try again?"
    user_input = uput
    if "y" in user_input or "yes" in user_input:
        start()
    elif "n" in user_input or "no" in user_input:
        sys.exit()
    else:
        try_again()


def mountain(x):
    i = 2
    while x > 0:
        print " " * x + "@" * i
        x -= 1
        i += 2

start()
它会起作用的

读取回溯:

def try_again():
    print "Would you like to try again?"
    user_input = uput()
    if "y" in user_input or "yes" in user_input:
        start()
    elif "n" in user_input or "no" in user_input:
        sys.exit()
    else:
        try_again()

该消息告诉您,您试图对
用户输入执行迭代,该迭代是由于
中的
语句而发生的

谢谢。现在我觉得自己很愚蠢,这是一个非常简单的错误。谢谢你的帮助。你的男人是拉斐尔@用户3583194嘿,简单的错误会发生!这一切都是关于阅读,有时并不明显,追溯。
def try_again():
    print "Would you like to try again?"
    user_input = uput()
    if "y" in user_input or "yes" in user_input:
        start()
    elif "n" in user_input or "no" in user_input:
        sys.exit()
    else:
        try_again()
TypeError: argument of type 'function' is not iterable