web-dev-qa-db-ja.com

TypeError:-: 'int'および 'list'のサポートされていないオペランドタイプ

pythonで、ツェラーアルゴリズムを使用して生まれた曜日を示すプログラムを作成しようとしています http://en.wikipedia.org/wiki/Zeller%27s_congruence しかし、それは私にこのエラーを与えています

TypeError:-: 'int'および 'list'のサポートされていないオペランドタイプ

何故ですか?

date = raw_input ("Introduce here the day, month and year you were born like this: DDMMYYYY")

if date.isdigit() and len(date) == 8:
    day = date[0:2]
    month = date[2:4]
    year = date[4:8]
    day = int(day)
    month = int(month)
    year = int(year)
    result = (day + (month + 1) * 2.6, + year % 100 + (year % 100) / 4 - 2 * [year / 100]) % 7

(これは私が自分で作成した最初のプログラムなので、どうぞよろしくお願いします;))

9
Esther28

あなたの直接の質問に答えて何が起こっているのかは@mellamokbとコメントによって答えられました...

ただし、Pythonはすでにこの組み込みであり、簡単にできることを指摘しておきます。

from datetime import datetime
d = datetime.strptime('1312981', '%d%m%Y')
# datetime(1981, 12, 13, 0, 0)

そうすれば、強制された文字列ではなく、実際にはdatetimeであるオブジェクトに対してより簡単に計算を実行できます。

4
Jon Clements

おもう 2 * [year / 100]は角かっこではなくかっこである必要があります。そうでない場合は、単一要素リストを作成することを示します。

(year % 100) / 4 - 2 * (year / 100))
                       ^          ^ change [] to ()
3
mellamokb