Hi,
I am trying to write a code that will calculate easter date within a year range.The problem i have is that no matter what date i put either within or outside the range i get the same output.Here is the code

    #A programme to calculate date of easter

    def main():
        year=input('Enter a year between 1982-2048 ')
        if year==range(1982,2049):
            a=year%19
            b=year%4
            c=year%7
            d=((19*a)+24)%30
            e=((2*b)+(4*c)+(6*d)+5)%7
            f=22+d+e
            if f<=31:
                        print " Easter in on March",f
                    else:
                        print "Easter is on April",f-31
        else:
                print 'Year is not within range'

    main()

Thanks for the help in advance.

User input can not be the whole range use in. Your indention is off for the if statement in lines 12-17.

Edited 4 Years Ago by pyTony

Try something like this:

# A program to calculate date of Easter

def calc_easter(year):

    if year in range(1982, 2049):
        a = year % 19
        b = year % 4
        c = year % 7
        d = ((19*a) + 24)%30
        e = ((2*b) + (4*c) + (6*d) + 5)%7
        f = 22 + d + e
        if f <= 31:
            print(" Easter in on March %d" % f)
        else:
            print("Easter is on April %d" % (f - 31))
    else:
        print("Year is not within range")

year = int(input('Enter a year between 1982-2048 '))
calc_easter(year)
This article has been dead for over six months. Start a new discussion instead.