Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: unsupported operand type(s) for -: 'int' and 'list'

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 ;) )

like image 961
Esther28 Avatar asked Dec 26 '12 14:12

Esther28


2 Answers

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...

like image 53
Jon Clements Avatar answered Sep 20 '22 05:09

Jon Clements


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 ()
like image 31
mellamokb Avatar answered Sep 23 '22 05:09

mellamokb