zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    VMware Workstation9安装Mac OS X10.9系统
    如何在windows下的Python开发工具IDLE里安装其他模块?
    Git在下搭建下环境的工具
    Git的安装与使用
    Linux(CentOs6.4)安装Git
    VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
    centos 6.5 升级内核 linux 3.12.17
    让CentOS系统时间同步
    编译安装LNMP Centos 6.5 x64 + Nginx1.6.0 + PHP5.5.13 + Mysql5.6.19
    64位CentOS5.6安装Mysql 5.5.11GA
  • 原文地址:https://www.cnblogs.com/cmnz/p/6898712.html
Copyright © 2011-2022 走看看