from calendar import monthrange, weekday y = int(input('input year: ')) m = int(input('input month: ')) w = ' Mo Tu We Th Fr Sa Su' D = monthrange(y, m)[1] # last day of the month F = weekday(y, m, 1) s = ' ' * (F+1) + ' '.join(map(str,range(1, 10))) + ' ' + ' '.join(map(str,range(10, D+1))) print(w, end='') for i, e in enumerate(s): print(e, end='\n' if i % len(w) == 0 or (i+1) == len(s) else '')