码迷,mamicode.com
首页 > 编程语言 > 详细

python小练习

时间:2016-09-23 16:47:52      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

写一个程序,用于计算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小练习

标签:

原文地址:http://www.cnblogs.com/sussie/p/5900453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!