概述
# -*- coding:utf-8 -*-
"""
计算当前时间是一年中的第几天
"""
bissextile = [31,60,91,121,152,182,213,244,274,305,335,366] #leap year
commonYear =[31,59,90,120,151,181,212,243,273,304,334,365]
enterYear = int(raw_input("enter the Year :"))
enterMonth = int(raw_input("enter the Month :"))
enterDay = int(raw_input("enter the Day :"))
remained = 0
# first need to check is leap or common year
if (enterYear%100 !=0) and (enterYear %4 == 0 ) or (enterYear%400 == 0):
if enterMonth > 1 :
remained = bissextile[enterMonth-1] + enterDay
else:
remained = enterDay
else:
if enterMonth > 1 :
remained = commonYear[enterMonth-1] + enterDay
else:
remained = enterDay
print remained
最后
以上就是多情钢笔为你收集整理的python计算一年有多少天_Python 案例 004 (计算当前时间是一年中的第几天)的全部内容,希望文章能够帮你解决python计算一年有多少天_Python 案例 004 (计算当前时间是一年中的第几天)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复