Python'str'对象不可调用Python 2.7.3

use*_*591 1 python string callable

我目前正在编写一个交易游戏,用户连接到服务器,然后互相交易并赚钱等等.但是当我尝试时

if(input.lower() == 'sell'):
        sMaterial = raw_input('Material: ')
        if(sMaterial.lower() == 'gold'):
            sAmount = int(input('Enter amount: '))
            if(gold >= sAmount):
                mon = mon + (100 * sAmount)
            else:
                print 'You do not have enough', sMaterial
Run Code Online (Sandbox Code Playgroud)

它抛出错误

> sell
Material: gold
Traceback (most recent call last):
  File "Test.py", line 119, in <module>
    sAmount = int(input('Enter amount: '))
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)

我使用Linux,Python版本2.7.3,与Geany开发环境.提前致谢.

DSM*_*DSM 10

这一行:

if(input.lower() == 'sell'):
Run Code Online (Sandbox Code Playgroud)

告诉我你必须input在某个时候将名字绑定到一个字符串.所以当你打电话

sAmount = int(input('Enter amount: '))
Run Code Online (Sandbox Code Playgroud)

你试图将参数传递'Enter amount: '字符串 input,因此:TypeError: 'str' object is not callable.因为看起来你正在使用Python 2,所以你应该使用raw_input无论如何,但这是不重新绑定内置名称的另一个原因.