DEV Community

Cover image for Easter Calculator
Scott Gordon
Scott Gordon

Posted on

2 1

Easter Calculator

# easter_calculator.py
#   This program takes a year as an input, verifies that it is in the proper
#   range, and then prints out the date of Easter that year.
# by: Scott Gordon

from datetime import datetime, timedelta

def main():
    print("Welcome To the Easter Calculator\n")
    print("Choose a year that you want to find the date of easter from 1982-2048")
    year = int(input("Please enter the year (yyyy) here: "))

    def easter_calc(year):
        """Takes year as input and prints out when Easter was that year."""
        a = year % 19
        b = year % 4
        c = year % 7
        d = ((19*a) + 24) % 30
        e = (2*b + 4*c + 6*d + 5) % 7

        start_date = datetime(year, 3, 22)
        format = "%m/%d/%y"
        easter = start_date + timedelta(d+e)

        if (year >= 1982) and (year <= 2048):
            return f"\nThe date of Easter is {easter.strftime(format)}"
        else:
            return f"\nSorry you must choose a year from 1982 to 2048."

    print(easter_calc(year))


if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

Photo by Annie Spratt on Unsplash

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay