python 万年历 以1800年开始

直接上代码,比较简单懒得写注释了

def is_leap_year(year):
    if(year%4==0 and year%100!=0) or (year%400==0):
        return 1
    else:
        return 0



def get_num_of_day_in_month(year,month):
    if month==2:
        if is_leap_year(year):
            days=29
        else:
            days=28
    elif month in[4,6,9,11]:
        days=30
    else:
        days=31
    return days


def get_total_num_of_day(year, month):
    yearday = 0
    for i in range(1800, year):
        if is_leap_year(i):
            yearday += 366
        else:
            yearday += 365
    for i in range(1, month):
        yearday += get_num_of_day_in_month(year, i)
    return yearday


def print_information_title(year,month):
    if year < 1800 :
        print("小于1800,请重新输入一个年份")
        return False
    else:
        print((str(year)+"年").ljust(10),end="")
        print((str(month)+"月").rjust(14))
        return True


year=int(input("请输入一个不小于1800年的年份"))
month=int(input("请输入月份"))
if  print_information_title(year,month):
    week=(get_total_num_of_day(year,month))%7
    test = week - 4 if week >= 4 else week + 3
    print('日\t一\t二\t三\t四\t五\t六\t')
    for i in range(0,test):
        print("\t",end="")
    for i in range(1,get_num_of_day_in_month(year,month)+1):
        if (get_total_num_of_day(year,month)+i)%7==4:
            print(i,end="\n")
        else:
            print(i,end="\t")
else:
    pass

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ana_ing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值