Deqin- function calculates the leap year and the number of days this year

More children's programming can contact Hou, micro-channel data_ecology
This link: https://blog.csdn.net/houlaos/article/details/102631056

To a number 20,190,318, print October 18, 2019

month_day = [31,28 ,31, 30, 31, 30 ,31 ,31, 30, 31, 30, 31]

def riqi(date):
    # 数据质量,闰年的问题
    print(date[0:4]+"年"+date[4:6]+"月"+date[6:8]+"日")
    month = int(date[4:6])
    day = int(date[6:8])
    a = 1
    days = 0
    while a<month:
        days = days+ month_day[a-1]
        a=a+1
    return "这是今年的第%d天"%(days+day)

s = '20191018'
print(riqi(s))

Guess you like

Origin blog.csdn.net/houlaos/article/details/102631056