Python 判断闰年,判断日期是当前年的第几天
http://www.cnblogs.com/vamei/archive/2012/07/19/2600135.html
Python小题目 针对快速教程 作业答案
写一个程序,判断2008年是否是闰年。
写一个程序,用于计算2008年10月1日是这一年的第几天?(2008年1月1日是这一年的第一天)
#判断闰年
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
#判断是这一年的第几天
def getDayInYear(year,month,day):
month_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if is_leap_year(year):
month_day[1]=29
return sum(month_day[:month - 1]) + day print(getDayInYear(2008,1,1))
print(getDayInYear(2008,10,1))
print(getDayInYear(2009,10,1))
也有现成的方法 time strftime() 参考该方法说明 点击链接 http://www.runoob.com/python/att-time-strftime.html
import datetime
def getDayInYear(year, month, day):
date = datetime.date(year, month, day)
return date.strftime('%j')
print(getDayInYear(2008,1,1))
print(getDayInYear(2008,10,1))
print(getDayInYear(2009,10,1))
Python 判断闰年,判断日期是当前年的第几天的更多相关文章
- jquery 获取日期 date 对象、 判断闰年
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- if语句判断闰年、平年
一.让用户输入一个年份,判断是否是闰年. 判断一个年份是否是闰年有两个条件 ①能被400整除:②能被4整除但是不能被100整除 Console.WriteLine("请输入年份:" ...
- JAVA中判断年月日格式是否正确(支持判断闰年的2月份)
一.先说一下年月日(yyyy-MM-dd)正则表达式: 1.年月日正则表达式:^((19|20)[0-9]{2})-((0?2-((0?[1-9])|([1-2][0-9])))|(0?(1|3|5| ...
- HDU 2005 第几天?(闰年判断)
传送门: acm.hdu.edu.cn/showproblem.php?pid=2005 第几天? Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- python学习——如何判断输入是数字
笨办法学python第35节 该节主要是讲分支与函数,主要遇到的问题是python中如何判断输入是数字. 首先原代码如下: from sys import exit def gold_room(): ...
- c#判断闰年
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php判断闰年
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- java练习题:解一元二次方程、判断闰年、判断标准身材、三个数取最大值
1.解一元二次方程 注:求根公式为(-b+根号德尔塔)/2a,(-b-根号德尔塔)/2a Scanner sc=new Scanner(System.in); System.out.println(& ...
- 判断闰年的方法以及如何获得单链表的倒数第K个元素
今天很悲催,心中向往的公司,打电话过来面试,问到我两个问题,结果竟然都没有回答上,伤心了,记录下今天失败,希望以后不要被同样的问题给PASS. 问题1.如何判断是否为闰年 所谓闰年那就是:四年一闰,百 ...
随机推荐
- ASPNET5 依赖注入(Dependency Injection)
依赖注入一直是asp.net web框架(Web API,SignalR and MVC)中不可或缺的一部分,但是在以前,这个框架都是各自升级,都有各自的依赖注入实现方式,即使Katana项目想通过O ...
- cpp - 编译过程
预处理 E:\CppSpace\hello>g++ -o main.i -E main.cpp E:\CppSpace\hello>dir /p 驱动器 E 中的卷是 固盘-项目 卷的序列 ...
- web-based installer and executable installer in python 3 ,what is the difference between them?
Welcome to Python! This applies to all programs, not just python: An executable installer has every ...
- 新建maven项目,JRE System Library[J2SE-1.5]
上篇博文中搭建了maven多模块项目,发现全是JRE System Library[J2SE-1.5],如图. 怎么避免这种情况呢? windows-preferences-maven-user se ...
- Android更新主线程UI的两种方式handler与runOnUiThread()
在android开发过程中,耗时操作我们会放在子线程中去执行,而更新UI是要主线程(也叫做:UI线程)来更新的,自然会遇到如何更新主线程UI的问题.如果在主线程之外的线程中直接更新页面显示常会报错.抛 ...
- 在nagios中使用python脚本监控linux主机
在被监控端192.168.5.1101.先把getload.py放到/usr/local/nagios/libexec内[root@nhserver1 ~]# vim /usr/local/nagio ...
- 【转】SHELL variables default value, ${var:-DEFAULT}和${var=DEFAULT}的一点区别
${var:-DEFAULT}和${var=DEFAULT}的区别: ${var:-DEFAULT} If var not set or is empty, evaluate expression a ...
- Gitlab备份与恢复[七]
标签(linux): git 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 备份 配置文件中加入 gitlab_rails['bakup_path']='/da ...
- FastDFS角色配置参数思维导图
- 企业级Docker私有仓库部署(https)
部署环境 Centos7.3 x64 docker-ce-17.06.0 docker-compose-1.15.0 Python-2.7.5(系统默认) 部署目标 使用HTTPS协议 支持Clair ...