Practice:输入年月日,判断该时间为一年的第几天
#-*- coding:utf- -*-
'''
Created on --
# 输入年月日,判断为一年的第几天
@author: AdministrInputator
''' def leapYear(year): # 判断平闰年,由于输入年份只有两位数,‘’~‘’转换为2000~,‘’~’‘转换为1970~
if year % == and year % != :
return True
else:
return False def dateJudge(strInput): # which day of the year
year = int(strInput[:])
month = int(strInput[:])
day = int(strInput[-:])
daysLeapYear = [, , , , , , , , , , , ] # days of months in leap year
daysNonLeapYear = [, , , , , , , , , , , ]
theDay = # the result
if len(strInput) != :
print(' 6 numbers limited!','\n','=-'*)
return
if month > :
print(' the month is not more than 12!','\n','=-'*)
return
if leapYear(year):
if day > daysLeapYear[month - ]:
print(' days of the month ',month,' cant\'t be larger than ',daysLeapYear[month - ],'!\n','=-'*)
return
if not leapYear(year):
if day > daysNonLeapYear[month - ]:
print(' days of the month ',month,' cant\'t be larger than ',daysNonLeapYear[month - ],'!\n','=-'*)
return
# calculate the day
if year < :
year +=
else:
year +=
if leapYear(year):
for index in range(, month - ):
theDay += daysLeapYear[index]
else:
for index in range(, month - ):
theDay += daysNonLeapYear[index]
theDay += day # add the day inputted to the result
# print(type(year))
print(' Input time:',year,'/',month,'/',day, ';''\n result:',theDay,'\n','=-'*)
# function call
dateJudge('')
dateJudge('')
dateJudge('')
dateJudge('')
dateJudge('')
dateJudge('')
运行结果:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Input time: 2015 / 2 / 28 ;
result: 59
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Input time: 1971 / 5 / 9 ;
result: 129
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Input time: 2015 / 12 / 31 ;
result: 365
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
6 numbers limited!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
days of the month 2 cant't be larger than 28 !
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
the month is not more than 12!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>>>
Practice:输入年月日,判断该时间为一年的第几天的更多相关文章
- 1121 if条件语句练习--输入年月日判断执行
<script type="text/javascript"> var a=prompt("请输入一个年","请输入年份"); ...
- 输入年月日判断是当年第几天(if判断)
- 自己设计一个日期类,可以输入年月日作为构造时的参数,如果不使用参数,则设定为1900年1月1日;编写一个方法equals判断两个日期是否相等;另一个方法compareTo可以进行日期之间的比较,返回两个日期之间相差的天数.
import java.util.*; import java.lang.Math; class Date1{ private int year; private int month; private ...
- Java判断当前时间是否在某一时间段内
今天有一个任务,判断现在的时间是否在某一个时间段内 遇到的第一个问题 Date类获取日期时间大的方法失效了 问题描述: 在学习Date类时,习惯性的用get方法调用Date()的年月日,发现不怎么好用 ...
- Java初学者作业——分析计费规则后,编写程序输入乘坐出租车的时间和里程数,计算里程价格
返回本章节 返回作业目录 需求说明: 某城市的出租车计费规则如下: 在 7:00 - 23:00 之间,3km 以内收取起步价 10 元,超过 3km 每 km 收取 2 元. 如果不在这个时间段,在 ...
- c# 判断当前时间是否在 工作日时间段内
#region //获取当前周几 private string _strWorkingDayAM = "08:30";//工作时间上午08:00 private string _s ...
- Java判断一个时间是否在另一个时间段内
需求:当时间在凌晨0点至0点5分之间程序不执行. 也就是实现判断当前时间点是否在00:00:00至00:05:00之间 方法: Java代码 : /** * 判断时间是否在时间段内 * * @para ...
- H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒
编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒. 如输入 2004 年 12 月 31 日 23 时 59 分 59 秒,则输出 2005年 1 月 1 日 0 时 0 分 0 秒. ...
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
应用中设置一般会存在这样的设置,如夜间勿扰模式,从8:00-23:00,此时如何判断当前时间是否在该时间段内.难点主要在于如何用NSDate生成一个8:00的时间和23:00的时间,然后用当前的时间跟 ...
随机推荐
- <<有效软件测试>> 读书笔记和自己的一些思考
需求阶段 1. 测试人员及早介入,需要彻底了解产品,设计测试过程 * 及早介入,可以了解在开发的过程中需要使用哪些新技术,新的平台, 测试组是否方便进行测试,是否方便进行自动化测试,早期开发和测试应该 ...
- [补充工程统计case]科技活动经费sql2014
select bd_glorgbook.glorgbookcode,bd_glorgbook.glorgbookname, gl_detail.explanation, bd_accsubj.disp ...
- 黄聪:wordpress向一个页面POST数据,出现404页面访问不了
出现这个情况,说明POST的数据中存在一些关键词,触发调用了page以外的模版.比如POST数据中有 name , author 等参数. 解决办法,就是把这些参数改一下名称.
- 使用jquery的delay方式模拟sleep
javascript中并没有原生sleep函数可供调用,一般来说为了实现sleep功能,大都是采用SetTimeout来模拟,以下片段采用jquery的delay方法来模拟,也算是提供了另外一个视角吧 ...
- RabbitMQ介绍6 - 其它
深入话题 Exchange实现路由的方法 http://www.rabbitmq.com/blog/2010/09/14/very-fast-and-scalable-topic-routing-pa ...
- mysql 联合索引(转)
http://blog.csdn.net/lmh12506/article/details/8879916 mysql 联合索引详解 联合索引又叫复合索引.对于复合索引:Mysql从左到右的使用索引中 ...
- 发送SMS短信(JSON) 转载
http://blog.csdn.net/ldl22847/article/details/42553883 public static string GetMobileConfByUserId( ...
- git patch
http://www.cnblogs.com/y041039/articles/2411600.html
- Linux ToolChain (二) --- Linker (1)链接选项 -L -rpath -rpath-link
一.动态库的链接和链接选项-L,-rpath-link,-rpath (1). 现代连接器在处理动态库时将链接时路径(Link-time path)和运行时路径(Run-time path)分开, 用 ...
- javascript立即执行函数 (function(){})()
看到一段代码: (function(){ var outer = $('#subject'); outer.find('li').on('mouseover', mouseover); })() ( ...