diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-10-10 14:57:59 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-10-10 14:57:59 +0800 |
| commit | 24c95169da60a6a449046084057f7d65cb2e237e (patch) | |
| tree | b2cc468e4154da5cabd7bb935fee5fd652f306cf /challenge-237/eric-cheung/python/ch-1.py | |
| parent | c1f9c3a1309d813f5fc706cb6af21eb9cf6658ac (diff) | |
| parent | 3ce214ad99d99c1edcae374b6eac3c16448216c8 (diff) | |
| download | perlweeklychallenge-club-24c95169da60a6a449046084057f7d65cb2e237e.tar.gz perlweeklychallenge-club-24c95169da60a6a449046084057f7d65cb2e237e.tar.bz2 perlweeklychallenge-club-24c95169da60a6a449046084057f7d65cb2e237e.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-237/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-237/eric-cheung/python/ch-1.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-237/eric-cheung/python/ch-1.py b/challenge-237/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..035ce42e26 --- /dev/null +++ b/challenge-237/eric-cheung/python/ch-1.py @@ -0,0 +1,40 @@ +
+from datetime import datetime
+from calendar import monthrange
+
+## Example 1
+nYearInput = 2024
+nMonthInput = 4
+nWeekDayMonth = 3
+nWeekDay = 2
+
+
+## Example 2
+## nYearInput = 2025
+## nMonthInput = 10
+## nWeekDayMonth = 2
+## nWeekDay = 4
+
+
+## Example 3
+## nYearInput = 2026
+## nMonthInput = 8
+## nWeekDayMonth = 5
+## nWeekDay = 3
+
+
+nLastDay = monthrange(nYearInput, nMonthInput)[1]
+
+nDay = 0
+for nLoop in range(1, 8):
+ objDateInput = datetime(nYearInput, nMonthInput, nLoop)
+ if objDateInput.isoweekday() == nWeekDay:
+ nDay = nLoop
+ break
+
+nDay = nDay + 7 * (nWeekDayMonth - 1)
+
+if nDay <= nLastDay:
+ print (nDay)
+else:
+ print (0)
|
