Python Forum
Printing Easter date occurrences
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing Easter date occurrences
#6
1. you don't need self in calc_easter(). It's not a class attribute. Thus you don't need to pass date as first argument when call it.
2. when you pass date you pass just generic datetime.date object (i.e. not an instance) and when you print date.month it's just the attribute month of that date object.

from datetime import date
 
def calc_easter(year):
    "Returns Easter as a date object."
    a = year % 19
    b = year // 100
    c = year % 100
    d = (19 * a + b - b // 4 - ((b - (b + 8) // 25 + 1) // 3) + 15) % 30
    e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7
    f = d + e - 7 * ((a + 11 * d + 22 * e) // 451) + 114
    month = f // 31
    day = f % 31 + 1    
    return date(year, month, day)
 
start_interval = 1950
end_interval = 2042
for year in range(start_interval, end_interval):
    easter = calc_easter(year=year)
    if easter.month == 4 and easter.day == 21:
        print(easter.strftime('%Y-%m-%d'))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Printing Easter date occurrences - by samsonite - Mar-05-2019, 08:22 AM
RE: Printing Easter date occurrences - by samsonite - Mar-05-2019, 04:38 PM
RE: Printing Easter date occurrences - by woooee - Mar-05-2019, 05:38 PM
RE: Printing Easter date occurrences - by samsonite - Mar-05-2019, 05:54 PM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 06:39 AM
RE: Printing Easter date occurrences - by buran - Mar-06-2019, 07:49 AM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 09:41 AM
RE: Printing Easter date occurrences - by buran - Mar-06-2019, 10:05 AM
RE: Printing Easter date occurrences - by samsonite - Mar-06-2019, 11:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 2,312 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 2,988 Jan-20-2024, 04:45 AM
Last Post: 1418
  Date format and past date check function Turtle 5 10,900 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,952 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Count number of occurrences of list items in list of tuples t4keheart 1 3,234 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  Count & Sort occurrences of text in a file oradba4u 7 4,946 Sep-06-2020, 03:23 PM
Last Post: oradba4u
  How to add date and years(integer) to get a date NG0824 4 4,092 Sep-03-2020, 02:25 PM
Last Post: NG0824
  Counting number of occurrences of a single digit in a list python_newbie09 12 8,976 Aug-12-2019, 01:31 PM
Last Post: perfringo
  Occurrences using FOR and IF cycle P86 2 3,386 Jul-29-2019, 04:37 PM
Last Post: ThomasL
  Substracting today's date from a date in column of dates to get an integer value firebird 1 2,748 Jul-04-2019, 06:54 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020