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的时间,然后用当前的时间跟 ...
随机推荐
- 面对一个新的MCU,我再也不敢说第一步是点灯了
折腾了几天AT91SAM3S,今天才算是把开发板上的3个LED点亮. 在点亮之前,起码看了百八十页的Datasheet,动用了N次百度. 各种时钟,看门狗,分散加载,中断向量,都得去整.这些都远远超过 ...
- Hibernate5.2之原生SQL查询
Hibernate5.2之原生SQL查询 一. 介绍 在上一篇博客中笔者通过代码的形式给各位读者介绍了Hibernate中最重要的检索方式--HQL查询.在本博文中笔者将向各位读者介绍Hiberna ...
- Nuget 管理entity framework
安装,带版本号 PM> Install-Package EntityFramework -Version 5.0.0 更新数据库 PM> Enable-Migrations -Contex ...
- powerDesigner 报Unable to connect SQLState=08004 解决方法
在使用PowerDesigner配置数据库连接(configure connections)的时候,点击Test connection之后弹出Unable to connect SQLState=08 ...
- 【转载】Securing Kibana + Elasticsearch
from: http://tom.meinlschmidt.org/2014/05/19/securing-kibana-elasticsearch/ After some successful se ...
- DataTable排序(转)
DataTable 排序 DataRow[] rows = dataTable1.Select("", "ord asc"); DataTable t ...
- 52. Sort Colors && Combinations
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...
- 对SSH三大框架的理解
SSH框架一般指的是Struts.Spring.Hibernate,后来Struts2代替了Struts.最近5年,Struts2已经被Spring MVC代替,而Hibernate基本也被iBati ...
- Python:if __name__ == '__main__'
很多模块里都会看到这句话,一般用于模块自测时使用. 所有的模块都有一个内置属性 __name__. 一个模块的 __name__ 的值取决于您如何应用模块. 一个Python文件有两种使用方式,直接使 ...
- springMVC使用与生成序列号
springMVC使用与生成序列号 我是以springMVC的方式提供序列号 代码可以直接在项目中用 第一步:controller类 @Autowired private PkGenerator pk ...