year = int(input("请输入年份"))
month = int(input("请输入月份:"))
if month == 1:
momthName,monthDays = "Jan",31
elif month == 2:
monthName = "Feb"
if (year %4== 0)and(year%100!=0)or(year%400 == 0):
monthDays = 29
else:
monthDay = 28
elif month == 3:
monthName,monthDays = "March",31
elif month == 4:
monthName,monthDays = "Apr",30
elif month == 5:
monthName,monthDays = "May",31
elif month == 6:
monthName,monthDays = "Jun",30
elif month == 7:
monthName,monthDays = "Jul",31
elif month == 8:
monthName,monthDays = "Aug",31
elif month == 9:
monthName,monthDays = "Sept",30
elif month == 10:
monthName,monthDays = "Oct",31
elif month == 11:
monthName,monthDays = "Nov",30
else:
monthName,monthDays = "Dec",31
#print(str(year)+"年"+monthName+"有"+str(monthDays)+"天")
#生成日历表头
message = "\t\t"+monthName+"\t"+str(year)+"\n"
message = message+"-"*4*7+"\n"
message = message + "Sun\tMon\tTue\tWed\tThu\tFri\tSat"+"\n"
#print(message)
if month ==1 or month ==2:
year = year-1
month = month+12
#使用蔡勒公式计算某年某月的第一天是周几
firstWeekDay = ((year%100)+(year%100//4)+(year//100//4)-(2*(year//100))+(26*(month+1)//10))%7
#firstWeekDay = ((1+(26*(month+1)//10)+(year%100)+(year%100//4)+(year//100//4)+(year//100*5))%7+6)%7
#print(firstWeekDay)
message = message + "\t"*firstWeekDay
#使用循环语句输出日历
for date in range (1,monthDays+1):
if (firstWeekDay+date)%7==0:
message = message+str(date)+"\n"
else:
message = message+str(date)+"\t"
print(message)