From 348adb792a21a38fdafbd4977e18ca4b29881ae5 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 3 Oct 2023 12:33:39 +0100 Subject: - 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. --- challenge-237/eric-cheung/python/ch-1.py | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 challenge-237/eric-cheung/python/ch-1.py (limited to 'challenge-237/eric-cheung/python/ch-1.py') 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) -- cgit