1 #!/usr/bin/python3
2 from datetime import datetime
3
4 import sys
5
6
7 def is_lear(year):
8 return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
9
10
11 def main():
12 if len(sys.argv) == 3:
13 month = int(sys.argv[1])
14 year = int(sys.argb[2])
15 else:
16 now = datetime.now()
17 month = now.month
18 year = now.year
19 print(f'{year}年{month}月')
20 m = month if month >= 3 else month + 12
21 y = year if month >= 3 else year - 1
22 c, y = y // 100, y % 100
23 w = y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10
24 month_words = ['January', 'February', 'March', 'April', 'May','Jun e', 'July', 'August', 'September', 'October', 'November', 'December']
25 title = month_words[month] + ' ' + str(year)
26 print(title.center(20))
27 print('Su Mo Tu We Th Fr Sa')
28 print(' ' * 3 * w, end='')
29 month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
30 days = month_days[month - 1]
31 if month == 2 and is_leap(year):
32 days += 1
33 for day in range(1, days + 1):
34 print(str(day).rjust(2, 0), end=' ')
35 w += 1
36 if w == 7:
37 print()
38 w = 0
39 print()
40 if __name__ == '__main__':
41 main()
万年历(蔡勒)公式
网友评论