TypeError:不支持的操作数类型 - :'int'和'list' [英] TypeError: unsupported operand type(s) for -: 'int' and 'list'
问题描述
我正在尝试在python中创建一个程序,它会告诉你使用Zeller算法出生的那一周 http://en.wikipedia.org/wiki/Zeller%27s_congruence 但它给了我这个错误
I'm trying to create a program in python that will tell you the day of the week you were born using the Zeller algorithm http://en.wikipedia.org/wiki/Zeller%27s_congruence but it's giving me this error
TypeError:不支持的操作数类型 - :'int'和'list'
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
(这是我自己创建的第一个程序,所以请好一点;)
(It's the first program I create by myself, so be nice please ;) )
推荐答案
@mellamokb回答了你的直接问题所发生的事情并发表评论...
What's happening in answer to your direct question has been answered by @mellamokb and comments...
然而,我会指出Python已经内置并且会更容易:
However, I would point out that Python already this builtin and would make it easier:
from datetime import datetime
d = datetime.strptime('1312981', '%d%m%Y')
# datetime(1981, 12, 13, 0, 0)
然后你可以更容易地对一个实际上是 datetime
的对象执行计算,而不是合成的字符串......
Then you can perform calculations more easily on an object that is actually a datetime
rather than co-erced strings...
这篇关于TypeError:不支持的操作数类型 - :'int'和'list'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!