编写函数来计算星期几

时间:2014-12-02 18:52:26

标签: python python-3.4

我的任务是:

  

编写一个函数来计算并返回给定年月,日和星期的星期几(整数)。使用Zellers一致性

我的代码:

DAYS = ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]

if month == 1:
    month = 13
    year -= 1
elif month == 2:
    month = 14
    year -= 1

century = str(year)[:1]
century_year = str(year)[2:]

century = int(century)
century_year = int(century_year)

h = (day_month+((26(month+1))//10+century_year)+(century_year//4)+(century//4)+(5*century))%7

day = DAYS[h]
return day 

当我尝试运行时,我得到了

    h = (day_month+((26(month+1))//10+century_year)+(century_year//4)+(century//4)+(5*century))%7
TypeError: 'int' object is not callable

1 个答案:

答案 0 :(得分:1)

我认为错误可能在乘法中。 h =(day_month +((26(月+ 1)......

当您编写26(月+ 1)时,Python认为您将26作为函数使用参数month + 1。您必须使用乘法符号" *"。

尝试写作: h =(day_month +((26 *(month + 1)...