
Calvin D. answered 09/26/22
Computer Scientist & US Air Force Cyber Security Officer
I'm not quite sure what that algorithm you posted is, but there's an easier way! Dates and times are a pain to work with manually, so we can ask python to do most of the dirty work for us.
We use the sys module to extract command line arguments, and use the zfill() function to make sure that the dates always have a leading zero if less than 2 characters. So for example, "9" turns into "09", and "25" would remain the same since its already 2 characters long.
Finally, we leverage python's datetime module to use the fromisoformat() function, plugging in the year, month, and date respectively into the argument. So it would make something like "2022-09-26".
With a date, the fromisoformat() function then does all of the internal calculations for the date, and allows us to ask it for the weekday number, which we do in the final line.
.....
Grace L.
Thanks!10/04/22