我正在尝试用python创建一个程序,它将使用Zeller算法http://en.wikipedia.org/wiki/Zeller%27s_congruence告诉您一周中您出生的那一天,但是它给了我这个错误
TypeError: unsupported operand type(s) for -: 'int' and '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
(这是我自己创建的第一个程序,请友好点;)
我认为
2 * [year / 100]
应该是圆括号而不是方括号,否则它表示您要创建一个元素列表:在回答你的直接问题时发生的事情已经被@mellamokb和评论回答了。。。
不过,我要指出的是,Python已经有了这个内置功能,这将使它更容易:
然后,您可以更容易地对实际为
datetime
的对象执行计算,而不是对字符串进行计算。。。相关问题 更多 >
编程相关推荐