I have tried to compute the date Easter falls on a particular year with this python program using the Anonymous Gregorian Computus Algorithm but I keep getting one error. My code block outputs the right result but I am finding it difficult to attach 'st' to the numbers in the 'st' list.
# Read the input from the user
year = int(input("Please enter a year to calculate the date of Easter: "))
a = year % 19
b = year // 100
c = year % 100
d = b // 4
e = b % 4
f =( b 8) // 25
g = (b - f 1) // 3
h = ((19 * a) b - d - g 15) % 30
i = c // 4
k = c % 4
l = (32 (2 * e) (2 * i) - h - k) % 7
m = (a (11 * h ) (22 * l)) // 451
month = (h l - (7 * m) (114)) // 31
day = 1 (( h l - (7 * m) (114)) % 31)
st = ['1', '21', '31']
nd = ['2', '22']
rd = ['3', '23']
th = ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '24', '25', '26', '27', '28', '29', '30']
if day in st:
print("In the year", year, "Easter will fall on the", str(day) "st", "of", month)
elif day in nd:
print("In the year", year, "Easter will fall on the", str(day) "nd", "of", month)
elif day in rd:
print("In the year", year, "Easter will fall on the", str(day) "rd", "of", month)
else:
print("In the year", year, "Easter will fall on the", str(day) "th", "of", month)
Using this algorithm, I have computed for different years to check if my code block is correct but when I compute for years like 2024 and 2040 that have their Easter dates falling on the days in the 'st' list, I keep getting '31th and 1th' instead of '31st and 1st'. I don't know what lines of code I am missing. If you can help me with this or tell me how best to compute this, I will really appreciate it.
PS: I have searched for other similar questions but the ones I have solved were in a totally different language and I didn't find one that used the Anonymous Gregorian Computhus Algorithm to compute the date of Easter.
Thank you.
CodePudding user response:
You can easily see your problem by using the Python interpreter:
$ python3
>>> st = ['1', '21', '31']
>>> 21 in st
False
>>> '21' in st
True
Strings and numbers are different things. You compute a number, so your test has to be with numbers.
$ python3
>>> st = [1, 21, 31]
>>> 21 in st
True
You should use sets instead of lists for inclusion tests. In this case, it doesn't make much difference but it's a good habit to get into in case there are lots of values.