# b 判断闰年
def funb(year):
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
return True
return False
# c 判断某月总天数
def func(year, month):
days = 31
if month == 2:
if funb(year):
days = 29
else:
days = 28
elif month in (4, 6, 9, 11):
days = 30
return days
# d 某年距离1900年的总天数
def fund(year):
res = 0
for i in range(1900, year):
if funb(i):
res += 366
else:
res += 365
return res
# e 某月距离当年1月1日的总天数
def fune(year, month):
res = 0
for i in range(1, month):
res += func(year, i)
return res
# f 根据d和e求总天数
def funf(year, month):
return fund(year) + fune(year, month)
# g 求某天是星期几
def fung(year, month):
res = funf(year, month)
# 当前天
week = (res+1) % 7
return week
# h 打印日历
def funh(year, month):
week = fung(year, month)
# print('week', week)
print('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', sep='\t')
# 星期week 空格
for i in range(week):
print(' ', end='\t\t')
for i in range(1, func(year, month)+1):
print(i, end='\t\t')
if (i+week) % 7 == 0:
print()
# a 获得年份和月份
def funa():
year = int(input('请输入年份:'))
month = int(input('请输入月份:'))
funh(year, month)
funa()
以1900年1月1日(星期一)为基准点 实现用户输入年份和月份打印当月的日历功能