Does this print a calendar?
#Sun = 0 Determination_of_the_day_of_the_week
def dayofweek(y, m, d):
t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
if( m < 3 ):
y -= 1
return (y + y//4 - y//100 + y//400 + t[m-1] + d) % 7
def leap(year):
return (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0))
def daysinmonth(year, month):
dm = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = dm[month-1]
if(month==2 and leap(year)):
d = 29
return d
def printmonth(y, m):
print("Mon Tue Wed Thu Fri Sat Sun")
bs = (dayofweek(y, m, 1)+6)% 7
print(' '*4*bs, end='')
dm = daysinmonth(y, m)
for x in range(1, 1+dm):
ender = ((bs+x)%7) and x!=dm
print('{:3}'.format(x), end=' ' if ender else '\n')
for m in range(1, 13):
printmonth(2021, m)