2017-01-25 8 views
-1

私はこの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で

+0

このエラーは、提供されたコードと一致しません。実際のコードを入力してください。 – Fejs

+0

申し訳ありません。ここにエラーがあります。 'if len(data)==(2(n_zero)-1): TypeError: 'int'オブジェクトは呼び出し可能ではない' – jamarumori

答えて

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

オペレータはなるべき:第二の例で

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

*。演算子を明示的に指定する必要があります。Pythonは、あなたがそれを伝えていなければ、それらの2つの数値を乗算すると仮定しません。

+0

ありがとうございました!私はアスタリスクを忘れた – jamarumori

2

ありがとう誤りであるです値の型。あなたの編集について

n_zero=int(input('Insert the amount of 0: ')) 

まさに何あなたが到達しようとしていますか?使用するよりも、乗算場合は*

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

ありがとうございました!アスタリスクを忘れました – jamarumori

関連する問題