diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-25 20:09:12 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-25 20:09:12 +0100 |
| commit | b404d135069bfbdf4fca5c9ff38ee4c3306e2a20 (patch) | |
| tree | a733ab92da893fc2c24f7d376c5cf9b0660c52c6 /challenge-175/eric-cheung/python/ch-1.py | |
| parent | a446030e38e1e414d4b0d70b6d8e35a207a5b061 (diff) | |
| download | perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.tar.gz perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.tar.bz2 perlweeklychallenge-club-b404d135069bfbdf4fca5c9ff38ee4c3306e2a20.zip | |
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-175/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-175/eric-cheung/python/ch-1.py | 21 |
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))
|
