aboutsummaryrefslogtreecommitdiff
path: root/challenge-175/eric-cheung/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-175/eric-cheung/python/ch-1.py')
-rwxr-xr-xchallenge-175/eric-cheung/python/ch-1.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-175/eric-cheung/python/ch-1.py b/challenge-175/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..214243d295
--- /dev/null
+++ b/challenge-175/eric-cheung/python/ch-1.py
@@ -0,0 +1,21 @@
+
+## Remark
+## https://stackoverflow.com/questions/42950/how-to-get-the-last-day-of-the-month
+
+import calendar
+
+
+nGivenYear = 2022
+nSunWeekNum = 6
+nWeekNumDay = 7
+
+
+for nMonthLoop in range(1, 13):
+ [nFirstDayWeekNum, nLastDay] = calendar.monthrange(nGivenYear, nMonthLoop)
+
+ nSunDay = 1 + nSunWeekNum - nFirstDayWeekNum + nWeekNumDay * 4
+
+ if nSunDay > nLastDay:
+ nSunDay = nSunDay - nWeekNumDay
+
+ print (str(nGivenYear) + "-" + ("0" + str(nMonthLoop) if nMonthLoop < 10 else str(nMonthLoop)) + "-" + str(nSunDay))