Python TypeError:';的操作数类型不受支持;int';和';列表';
我正在尝试用python创建一个程序,它会告诉你你出生的那一天使用的是Zeller算法,但它给了我这个错误 TypeError:-:“int”和“list”的操作数类型不受支持 为什么呢Python TypeError:';的操作数类型不受支持;int';和';列表';,python,list,int,typeerror,Python,List,Int,Typeerror,我正在尝试用python创建一个程序,它会告诉你你出生的那一天使用的是Zeller算法,但它给了我这个错误 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]
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]
应该是括号而不是括号,否则它表示您想要制作一个单一元素列表:
(year % 100) / 4 - 2 * (year / 100))
^ ^ change [] to ()
@mellamokb和评论已经回答了您直接问题的答案 但是,我要指出,Python已经具备了这一内置功能,这将使它变得更容易:
from datetime import datetime
d = datetime.strptime('1312981', '%d%m%Y')
# datetime(1981, 12, 13, 0, 0)
然后,您可以更轻松地对实际上是
日期时间的对象执行计算,而不是复杂的字符串…[year/100]
将此更改为:(year/100)
,也可以在(day+(month+1)*2.6
中,右括号在哪里?(删除,
)加上,
之后的2.6
也是一个错误。谢谢大家的回答!我做了这个和逗号的事情,它工作了!