交作业 日历

def is_leap_year(year):
    #判断闰年
    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        return True
    else:
        return False


def get_month_days(year, month):
    #判断哪一年哪一月有几天
    days = 31
    if month == 2:
        days = 29 if is_leap_year(year) else 28
    elif month in [4, 6, 9, 11]:
        days = 30
    return days


def get_today(year, month):
    #判断到之前共有多少天
    total = 0
    for i in range(1990, year):
        if is_leap_year(year):
            total += 366
        else:
            total += 365
    for i in range(1, month):
        total += get_month_days(year, i)
    return total

if __name__ == '__main__':

    while True:
        year = input('请输入年份, (如: 1990): ')
        month = input('请输入月份: (如:1): ')
        try:
            year = int(year)
            month = int(month)
            if month < 1 or month > 12:
                print("年份或月份输入错误,请重新输入!")
                continue
        except:
            print("年份或月份输入错误,请重新输入!")
            continue
        break

    print("日\t一\t二\t三\t四\t五\t六")
    count = 0
    for i in range((get_today(year, month) % 7) + 1):
        print("\t", end="")
        count += 1
    for i in range(1, (get_month_days(year, month)+1)):
        print(i, end="")
        print("\t", end="")
        count += 1
        if count % 7 == 0:
            print("\n")
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一直想不到要画什么样的形象页,在网上搜了张壁纸的图,临摹的。 由于形象页是圆形的,所以弄了个日历式的月计划。。英文...
    墨语筱言阅读 224评论 2 1
  • 正式交稿前来张不着边的,麻烦心蓝老师给点评下。谢谢啦!这是画具刚收到时我大儿(13岁,没上过正式绘画课程)花两个小...
    幸运如我阅读 446评论 1 2
  • 水中月 你高悬辽阔的天际,闪耀 我坠落世俗的深潭,迷离 遙遥仰望,脉脉情牵 不知相思几光年 艳羡浩瀚星河里,与你亲...
    AA阳光灿烂阅读 349评论 0 0
  • 将数据与地理信息叠加生产出数据地图,是近年来数据新闻生产的一种重要方式。不过地图生成一度是web上最困难的任务之一...
    媒文化的章伯阅读 19,445评论 3 49