Sunday, February 03, 2019

I'm tired of typing month/day/year once a month...

Quick code for listing month/day/year in Python.  I believe [0] is the first weekday of the month.  Weird little function/library.  There are a lot of variations to play with: https://docs.python.org/2/library/calendar.html

import datetime, calendar
year = 2019
month = 1
num_days = calendar.monthrange(year, month)[1]
for i in range(1,num_days+1):
    print(str(month) + "/" + str(i) + "/" + str(year) + ": ")

Acceptance criteria failure! My numbers are first to last, I want last to first.  So the range gets modified.

import datetime, calendar
year = 2019
month = 2
num_days = calendar.monthrange(year, month)[1]
for i in range(num_days, 0, -1):
    print(str(month) + "/" + str(i) + "/" + str(year) + ": ")

No comments: