• python_自定日历


    >>> from datetime import date
    >>> daysOfMonth=[31,28,31,30,31,30,31,31,30,31,30,31]

    >>> def myCalendar(year,month):
    start=date(year,month,1).timetuple().tm_wday
    print('{0} year {1} month'.format(year,month).center(56))
    print('t'.join('Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split()))
    day =daysOfMonth[month-1]
    if month==2:
    if year%400==0 or (year%4==0 and year%100!=0):
    day +=1
    result=[' '*8 for i in range(start+1)]
    result+=list(map(lambda d:str(d).ljust(8),range(day+1)))
    for i,day in enumerate(result):
    if i!=0 and i%7==0:
    print()
    print(day,end='')
    print()

    >>> def main(year,month=-1):
    if type(year)!=int or year<1000 or year>10000:
    print('Year error')
    return
    if type(month)==int:
    if month==-1:
    for m in range(1,13):
    myCalendar(year,m)
    elif month in range(1,13):
    myCalendar(year,month)
    else:
    print('Month error')
    return
    else:
    print('Month error')
    return

    >>> main(2017)
    2017 year 1 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday

    0 1 2 3 4 5 6
    7 8 9 10 11 12 13
    14 15 16 17 18 19 20
    21 22 23 24 25 26 27
    28 29 30 31
    2017 year 2 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28
    2017 year 3 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31
    2017 year 4 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30
    2017 year 5 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2 3 4 5
    6 7 8 9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28 29 30 31
    2017 year 6 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2
    3 4 5 6 7 8 9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
    2017 year 7 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31
    2017 year 8 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2 3 4
    5 6 7 8 9 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30 31
    2017 year 9 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1
    2 3 4 5 6 7 8
    9 10 11 12 13 14 15
    16 17 18 19 20 21 22
    23 24 25 26 27 28 29
    30
    2017 year 10 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday

    0 1 2 3 4 5 6
    7 8 9 10 11 12 13
    14 15 16 17 18 19 20
    21 22 23 24 25 26 27
    28 29 30 31
    2017 year 11 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30
    2017 year 12 month
    SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
    0 1
    2 3 4 5 6 7 8
    9 10 11 12 13 14 15
    16 17 18 19 20 21 22
    23 24 25 26 27 28 29
    30 31

  • 相关阅读:
    【BZOJ3626】【LNOI2014】—Lca(树链剖分)
    【BZOJ2434】【NOI2011】—阿狸的打字机(AC自动机+线段树)
    【UVA10498】—Happiness(线性规划/单纯形算法)
    【BZOJ4736】【清华集训2016】—温暖会指引我们前行(LCT)
    【BZOJ3451】【Tyvj1953】—Normal(点分治+NTT)
    【SCOI2019】—DAY2T1 湖之精灵的游戏(凸包+二分)
    【BZOJ4817】【SDOI2017】—树点涂色(LCT+树链剖分+线段树)
    【SCOI2019】—DAY2T1 RGB(容斥)
    Stargazer的分治讲义
    python datetime 模块
  • 原文地址:https://www.cnblogs.com/cmnz/p/6898712.html
Copyright © 2020-2023  润新知