#-*- 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:输入年月日,判断该时间为一年的第几天的更多相关文章

  1. 1121 if条件语句练习--输入年月日判断执行

    <script type="text/javascript"> var a=prompt("请输入一个年","请输入年份"); ...

  2. 输入年月日判断是当年第几天(if判断)

  3. 自己设计一个日期类,可以输入年月日作为构造时的参数,如果不使用参数,则设定为1900年1月1日;编写一个方法equals判断两个日期是否相等;另一个方法compareTo可以进行日期之间的比较,返回两个日期之间相差的天数.

    import java.util.*; import java.lang.Math; class Date1{ private int year; private int month; private ...

  4. Java判断当前时间是否在某一时间段内

    今天有一个任务,判断现在的时间是否在某一个时间段内 遇到的第一个问题 Date类获取日期时间大的方法失效了 问题描述: 在学习Date类时,习惯性的用get方法调用Date()的年月日,发现不怎么好用 ...

  5. Java初学者作业——分析计费规则后,编写程序输入乘坐出租车的时间和里程数,计算里程价格

    返回本章节 返回作业目录 需求说明: 某城市的出租车计费规则如下: 在 7:00 - 23:00 之间,3km 以内收取起步价 10 元,超过 3km 每 km 收取 2 元. 如果不在这个时间段,在 ...

  6. c# 判断当前时间是否在 工作日时间段内

    #region //获取当前周几 private string _strWorkingDayAM = "08:30";//工作时间上午08:00 private string _s ...

  7. Java判断一个时间是否在另一个时间段内

    需求:当时间在凌晨0点至0点5分之间程序不执行. 也就是实现判断当前时间点是否在00:00:00至00:05:00之间 方法: Java代码 : /** * 判断时间是否在时间段内 * * @para ...

  8. H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒

    编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒. 如输入 2004 年 12 月 31 日 23 时 59 分 59 秒,则输出 2005年 1 月 1 日 0 时 0 分 0 秒. ...

  9. ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。

    应用中设置一般会存在这样的设置,如夜间勿扰模式,从8:00-23:00,此时如何判断当前时间是否在该时间段内.难点主要在于如何用NSDate生成一个8:00的时间和23:00的时间,然后用当前的时间跟 ...

随机推荐

  1. OGNL语言

                                                             OGNL 一.概述 以下内容摘自Ognl的官网: OGNL stands for Ob ...

  2. razor 拼接字符串

    在asp.net引擎中 拼接字符串可以这样写 <script src="~/script/<%=scriptname%>.js"></script&g ...

  3. NserviceBus+rabbitmq

    Ok so I figured this out after looking a bit at the code and the requirements for amqp URI and it sh ...

  4. 智能指针 ADO数据库连接

    ADO库包含三个基本接口:_ConnectionPtr接口._CommandPtr接口和_RecordsetPtr接口._ConnectionPtr接口返回一个记录集或一个空指针.通常使用它来创建一个 ...

  5. Functional testing - python, selenium and django

    Functional testing  - python selenium django - Source Code : from selenium import webdriverfrom sele ...

  6. Selenium + PhantomJS + python 简单实现爬虫的功能

    Selenium 一.简介 selenium是一个用于Web应用自动化程序测试的工具,测试直接运行在浏览器中,就像真正的用户在操作一样 selenium2支持通过驱动真实浏览器(FirfoxDrive ...

  7. 洛谷P3371 【模板】单源最短路径

    P3371 [模板]单源最短路径 282通过 1.1K提交 题目提供者HansBug 标签 难度普及/提高- 提交  讨论  题解 最新讨论 不萌也是新,老司机求带 求看,spfa跑模板40分 为什么 ...

  8. c/c++ 对象内存布局

    一.对象内存查看工具 VS 编译器 CL 的一个编译选项可以查看 C++ 类的内存布局,非常有用.使用如下,从开始程序菜单找到 Visual Stdio 2012. 选择 VS 的命令行工具,按如下格 ...

  9. IO同步、异步与阻塞、非阻塞

    一.同步与异步同步/异步, 它们是消息的通知机制 1. 概念解释A. 同步所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回. 按照这个定义,其实绝大多数函数都是同步调用(例如si ...

  10. js图片变换

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...