0

我试图创建以下内容,以便在我去的时候重新分配变量。

def train(old_strength, old_energy): 
    train = input("What would you like to do now?\n'strentgh' or 'rest'\n>")

    if train == 'strength':
        strength = old_strength+10
        energy = old_energy-10


        if energy <= 0:
            print ("You do not have enough energy to do this.")

        else:   
            pass

        print ("You have gained 10 strength, and now have %d strength and %d energy left" %(strength, energy))
        old_strength = strength)
        old_energy = energy)        
        train(old_strength, old_energy)

我试图得到它,以便当它回到“训练”输入时,它将在下一次使用新的力量和能量值。目前我收到错误

Traceback (most recent call last):
  File "settler.py", line 127, in <modul
    train(10, 50)
  File "settler.py", line 37, in train
    train(old_strength, old_energy)
TypeError: 'str' object is not callable

我该如何解决?提前谢谢了

4

1 回答 1

4

def train(....)str书面形式辞职train = input(...)

这就是为什么你得到TypeError: 'str' object is not callable.

使用其他变量进行捕获input

编辑:

在您的第二个if语句 ( energy <= 0) 中,也许值得做的不仅仅是打印通知?喜欢return?或至少将最后 4 行包含在else块中。但这只是一个自由的想法,也许你才刚刚开始。

于 2013-10-28T21:25:03.733 回答