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: unsupported operand type(s) for -: 'int' and 'list'
Why is that?
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 ;) )
What's happening in answer to your direct question has been answered by @mellamokb and comments...
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)
Then you can perform calculations more easily on an object that is actually a datetime
rather than co-erced strings...
I think 2 * [year / 100]
should be parentheses instead of brackets, otherwise it indicates you want to make a single-element list:
(year % 100) / 4 - 2 * (year / 100))
^ ^ change [] to ()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With