Skip to content

every_day.py #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Find number of times every day occurs in a Year
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# python program Find number of
# times every day occurs in a Year


import datetime
import calendar

def day_occur_time(year):

# stores days in a week
days = [ "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
"Sunday" ]

# Initialize all counts as 52
L = [52 for i in range(7)]

# Find the index of the first day
# of the year
pos = -1
day = datetime.datetime(year, month = 1, day = 1).strftime("%A")
for i in range(7):
if day == days[i]:
pos = i

# mark the occurrence to be 53 of 1st day
# and 2nd day if the year is leap year
if calendar.isleap(year):
L[pos] += 1
L[(pos+1)%7] += 1

else:
L[pos] += 1


# Print the days
for i in range(7):
print(days[i], L[i])


# Driver Code
year = 2019
day_occur_time(year)