首页 > 代码库 > python小练习

python小练习

写一个程序,用于计算2016年9月23日是这一年的第几天?

def isLeap(year):    #year=input("please enter year:")    try:        if year%4==0 and year%100!=0:            return True        elif year%400==0:            return  True        else:            return False    except:        return your enter is not year!print isLeap(2016)def daysss(year,month,date):    m30=[4,6,7,9,11]    m31=[1,3,5,8,10,12]    days=0    for i in range(1,month):        if i in m30:            days=days+30        elif i in m31:            days=days+31        elif i==2 and isLeap(year):            days=days+29        elif i==2 or isLeap(year):            days=days+28        else:            return "your enter is incorrect!"    days=days+date    print days    return %d-%d-%d is the %d days in %d year %(year,month,date,days,year)print daysss(2016,9,23)

 

python小练习