#!/usr/local/python3
import datetime
import sys
def is_leap(year):
return ((year % 4 == 0 and year % 100 !=0) or year % 400 == 0)
def get_days(year,month):
days_of_month = [
0,31,28,31,30,31,30,31,31,30,31,30,31
]
days = days_of_month[month]
return days + 1 if is_leap(year) and month == 2 else days
def main():
if len(sys.argv) == 3:
month = int(sys.arg[1])
year = int(sys.argc[2])
else:
curr_date = datetime.datetime.now()
year = curr_date.year
month = curr_date.month
m = month + 12 if month < 3 else month
y = year - 1 if month < 3 else year
c,y = y // 100 ,y % 100
w = y+ y// 4 + c//4 -2 * c + 26 * (m+1) // 10
w %= 7
month_names = [
'','January','February','March','April','May','June','July','August','Septemper','October','November','December'
]
print(f'{month_names[month]} {year}'.center(20))
print('Su Mo Tu We Th Fr St')
print(' ' * 3 * w,end='')
days = get_days(year,month)
for day in range(1,days + 1):
print(f'{day}'.rjust(2),end=' ')
w += 1
if w == 7:
print()
w = 0
print()
if __name__ == "__main__":
main()
一键复制
编辑
Web IDE
原始数据
按行查看
历史