打印月历头歌课程设计

def month_calendar():
    year,month=get_year_month()
    date=date_of_first_day(year,month)
    days=days_of_month(year,month)
    print_calendar(year,month,date,days)

def get_year_month():
    year=eval(input("请输入年份"))
    month=eval(input("请输入月份"))
    return year,month
def date_of_first_day(year,month):
    day=1

    y0=year-(14-month) //12

    x=y0+y0//4-y0//100+y0//400

    m0=month+12*((14-month)//12)-2

    d0=(day+x+(31*m0)//12)%7

    return d0

def is_leap_year(year):

    isLeapYear=(year%4==0)

    isLeapYear =isLeapYear and (year%100!=0)

    isLeapYear =isLeapYear or (year%400==0)

    return isLeapYear

def days_of_month(year,month):

    days=0

    if month in [1,3,5,7,8,10,12]:
        days=31

    elif month in [4,6,9,11]:
        days=30

    else:
        if is_leap_year(year):
            days=29
        else:
            days=28
    return days

def print_calendar(year,month,date,days):

    print_head(year,month)

    print_body(date,days)

def print_head(year,month):
    print('\t\t{}年{}月'.format(year,month))
    print('日\t一\t二\t三\t四\t五\t六')

def print_body(date,days):


    count=date

    for i in range(date):
        print('\t',end='')

    for d in range(1,days+1):

        print(str(d)+'\t',end="")

        count=(count+1)%7
        if count ==0:

            print()

    print()
if __name__ == '__main__':
    month_calendar()

你可能感兴趣的:(python,前端,数据库)