Python 无法调用公式中的变量

Python 无法调用公式中的变量,python,arrays,python-2.7,if-statement,Python,Arrays,Python 2.7,If Statement,我正在做python编程,遇到了一个问题。 当我将n_zero的值放入条件语句中时,程序无法调用它 这是节目单 import numpy as np n_zero=int(input('Insert the amount of 0: ')) n_one =int(input('Insert the amount of 1: ')) n_two =int(input('Insert the amount of 2: ')) n_three = int(input('Insert the amo

我正在做python编程,遇到了一个问题。 当我将n_zero的值放入条件语句中时,程序无法调用它

这是节目单

import numpy as np

n_zero=int(input('Insert the amount of 0:  '))
n_one =int(input('Insert the amount of 1: '))
n_two =int(input('Insert the amount of 2: '))
n_three = int(input('Insert the amount of 3: '))

data = [0]*n_zero + [1]*n_one + [2]*n_two + [3]*n_three
print len(data)

if len(data)==(2(n_zero)-1):
    np.random.shuffle(data)
    datastring = ''.join(map(str, data))
    print ("Data string is : %s " % datastring )


else:
    print(error)
这就是错误所在

    if len(data)==(2(n_zero)-1):
TypeError: 'int' object is not callable

谢谢

在python中,您没有强制转换left value变量,因为您没有指定left value类型

n_zero=int(input('Insert the amount of 0:  '))
关于您的编辑:

你到底想联系什么?如果相乘,则使用运算符*

if len(data)==(2*(n_zero)-1):
    ...
应成为:

if len(data) == (2 * (n_zero) - 1):

注意第二个示例中的
*
。您必须显式提供运算符,如果您不告诉它,Python不会假定您要将这两个数字相乘。

此错误与提供的代码不匹配。请提供实际代码。对不起。这里是错误<代码>如果len(data)==(2(n_零)-1):TypeError:“int”对象不可调用谢谢!我忘了带星号谢谢!我忘了带星号
if len(data) == (2 * (n_zero) - 1):