中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起便开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”?(Python)

中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起便开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”?(Python)

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

def countDay(currentDay):
    perMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
    totalDay = 0
    year = 1990

    while year < currentDay['year']:
        if isLeapYear(year) == 1:
            totalDay += 366
        else:
            totalDay += 365
        year += 1

    if isLeapYear(currentDay['year']) == 1:
        perMonth[2] += 1

    i = 0
    while i < currentDay['month']:
        totalDay += perMonth[i]
        i += 1

    totalDay += currentDay['day']
    return totalDay

if __name__ == '__main__':
    print("Please input 指定日期 包括年,月,日 如:1999 1 31")
    year, month, day = [int(i) for i in input().split()]
    today = {'year': year, 'month': month, 'day': day}
    totalDay = countDay(today)
    print("%d年%d月%d日与1990年1月1日相差%d天" % (year, month, day, totalDay))

    result = totalDay % 5
    if 0 < result < 4:
        print("今天打鱼")
    else:
        print("今天晒网")

结果:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值