我正在编写一个脚本来计算 1900 年至 2099 年的复活节日期。问题是,对于 4 年(1954、1981、2049 和 2076),公式略有不同(即,日期已关闭 7天)。
def main():
print "Computes the date of Easter for years 1900-2099.\n"
year = input("The year: ")
if year >= 1900 and year <= 2099:
if year != 2049 != 2076 !=1981 != 1954:
a = year%19
b = year%4
c = year%7
d = (19*a+24)%30
e = (2*b+4*c+6*d+5)%7
date = 22 + d + e # March 22 is the starting date
if date <= 31:
print "The date of Easter is March", date
else:
print "The date of Easter is April", date - 31
else:
if date <= 31:
print "The date of Easter is March", date - 7
else:
print "The date of Easter is April", date - 31 - 7
else:
print "The year is out of range."
main()
Exerything 运行良好,但计算时间为 4 年。
我得到的是:
if date <= 31:
UnboundLocalError: local variable 'date' referenced before assignment
每当我输入任何 4 年作为输入时。