diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-03 12:33:39 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-03 12:33:39 +0100 |
| commit | 348adb792a21a38fdafbd4977e18ca4b29881ae5 (patch) | |
| tree | 39940d25cbe229d62f35fbfc107cf09a714bd8f9 /challenge-237/eric-cheung/python/ch-1.py | |
| parent | 100b1847395389d1f7fcc80957f463208f5f25e1 (diff) | |
| download | perlweeklychallenge-club-348adb792a21a38fdafbd4977e18ca4b29881ae5.tar.gz perlweeklychallenge-club-348adb792a21a38fdafbd4977e18ca4b29881ae5.tar.bz2 perlweeklychallenge-club-348adb792a21a38fdafbd4977e18ca4b29881ae5.zip | |
- Added solutions by Eric Cheok-Yin.
- Added solutions by Robert DiCicco.
- Added solutions by PokGoPun.
- Added solutions by rcmlz.
- Added solutions by David Ferrne.
- Added solutions by W. Luis Mochan.
- Added solutions by Peter Meszaros.
- Added solutions by E. Choroba.
- Added solutions by Luca Ferrari.
- Added solutions by Thomas Kohler.
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)
|
