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的时间,然后用当前的时间跟 ...
随机推荐
- SQL Server 2008 数据库镜像部署实例之三 配置见证服务器
SQL Server 2008 数据库镜像部署实例之三 配置见证服务器 前面已经完成了镜像数据库的配置,并进行那个了故障转移测试.接下来将部署见证服务器,实现自动故障转移. 一.关于见证服务器 1.若 ...
- vim(5)vim下wimrc的配置,解决中文乱码问题
解决linux下vim乱码的情况:(修改vimrc的内容) 全局的情况下:即所有用户都能用这个配置 文件地址:/etc/vimrc 在文件中添加: ,ucs-bom,gb18030,gbk,gb231 ...
- C++模板元编程 - 挖新坑的时候探索到了模板元编程的新玩法
C++真是一门自由的语言,虽然糖没有C#那么多,但是你想要怎么写,想要实现什么,想要用某种编程范式或者语言特性,它都会提供. 开大数运算类的新坑的时候(又是坑),无意中需要解决一个需求:大数类需要分别 ...
- Android Gradle 技巧之一: Build Variant 相关
Build Variant android gradle 插件,允许对最终的包以多个维度进行组合. BuildVariant = ProductFlavor x BuildType 两个维度 最常见的 ...
- Blackfin DSP(七):用SPORT口模拟SPI
1.问题的提出 当系统从SPI device启动时,若SCLK = 133M,则SPI的最大速度为33M.然而,有一些串行的flash设备能更快的运行,因此,如果我们使用SPORT口,它的最大速度为S ...
- Ubuntu-tomcat7目录
ubuntu下通过apt-get install tomcat7方式安装的tomcat目录分布如下,做个记录: user@myserver:/var/lib/tomcat7$ ls -lttotal ...
- python中subprocess.Popen.poll
import subprocess proc = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE) while 1: pr ...
- Spring:No bean named 'beanScope' is defined
初学Spring,“No bean named 'beanScope' is defined”这个问题困扰了我好几个小时,查资料无果后,重写好几遍代码后发现问题居然是配置文件不能放在包里...要放在s ...
- finder文件目录跳转快捷键
finder文件目录跳转快捷键 command+shift+G
- 10,SFDC 管理员篇 - 流程自动化
1,Process Builder Setup | Build | Create | Workflow & Approvals | Process Builder 当我们在对象中创建或者修改一 ...