Python中判断是否为闰年,求输入日期是该年第几天
#coding = utf-8
def getLastDay():
y = int(input("Please input year :"))
m = int(input("please input month :"))
d = int(input("Please input day :"))
s=0
if y <1:
y=1
if m <1:
m=1
if m>12:
m=12
if d <1:
d=1
mothday=[31,28,31,30,31,30,31,31,30,31,30,31]#一年中每个月的天数
month=mothday[m-1]#获取输入月份的天数
if d > mothday[m-1]:#判断输入日期是否大于该月天数
d=d-mothday[m-1]
m+=1
month=mothday[m-1]#输入天数大于当月天数后月份加一,重新计算新月天数
if m>12:
m=12
def runnian(y,s):#判断是否为闰年
t=0
if (y%400)==0:
print "是闰年"
t=1
s+=1#如果是闰年天数加1
elif (y%100)!=0 and (y%4)==0 :
print "是闰年"
t=1
s+=1#如果是闰年天数加1
else :
print "不是闰年"
t=0
s=0
return t,s
t,s=runnian(y,s)
if m==2:
month= month + t
print month #返回该月是多少天
for i in range(0,m-1):
s= s+ int(mothday[i])
s=s+d
print s #返回该日期是该年多少天
getLastDay()
Python中判断是否为闰年,求输入日期是该年第几天的更多相关文章
- python中对两个 list 求交集,并集和差集
python中对两个 list 求交集,并集和差集: 1.首先是较为浅白的做法: >>> a=[1,2,3,4,5,6,7,8,9,10] >>> b=[1,2,3 ...
- python中的递归问题,求圆周率
以上面一个公式为例: import numpy as np def getPi(n): if n == 0: return np.power(-1,n)*(1.0/(2*n+1)) else: ret ...
- python中判断为None
python中经常会有判断一个变量是否为None的情况,这里列举三种方式: if not x if x is None if not x is None *********************** ...
- python中判断readline读到文件末尾
fp = open('somefile.txt') while True: line = fp.readline() if not line: #等价于if line == "": ...
- python中判断对象类型的函数——isinstance
isinstance是Python中的一个内建函数.是用来判断一个对象的变量类型. isinstance(object, class-or-type-or-tuple) 如果参数object是clas ...
- python中判断输入是否为数字(包括浮点数)
1.当num确定为数字后 num=123.4print(isinstance(num,float))#判断是否为浮点数 print(isinstance(num,int))#判断是否为整数 2.当nu ...
- Python中判断输入字符串是否为数字的方法
在写物理实验图像处理的脚本时,遇到了一个判断输入的字符串是否为数字的方法 最开始我的思路是这个 test = input() while test.isdigit(): # do something ...
- python中判断语句用两个or连接的奇葩
学python的时候犯的一个错误,放在这吧.就是在循环某个列表的时候不要去操作它,这是容易忽略的一个地方.所以如果要操作某个列表本身,那么先把该列表copy一份,然后再读取的时候读copy的那份.操作 ...
- python中判断两个对象是否相等
#coding=utf-8#比较两个对象是否相等#python 2中使用cmp(),==,is#is 主要是判断 2 个变量是否引用的是同一个对象,如果是的话,则返回 true,否则返回 false. ...
随机推荐
- Caffe学习系列(11):数据可视化环境(python接口)配置
参考:http://www.cnblogs.com/denny402/p/5088399.html 这节配置python接口遇到了不少坑. 1.我是利用anaconda来配置python环境,在将ca ...
- CodeVS 1344 线型网络
Sol 随机化算法+哈密顿路径. 好厉害的题...首先都会想到状压DP对吧,复杂度 \(O(n^2 2^n)\) . \(n=20\) exm?? \(10^8\) 有一种算法就是随机化算法 再调整 ...
- pycharm3.4 下svn 项目checkout&配置
pycharm 社区版: 3.4 1. checkout 项目 注意,之前配置好:设置里面的一些配置:(以下勾勾不要勾上) 2. checkout 项目之后,做以下操作: vcs ->enabl ...
- Valid Number
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- C#值数值类型转换
1.十进制转16进制 string result=number.ToString("X2"); >>0A //X2表示大写2位 2.字符串转数值类型 "); ...
- POJ 1458 1159
http://poj.org/problem?id=1458 一道容易的DP,求最长公共子序列的 dp[i][j],代表str1中的第i个字母和str2中的第j个字母的最多的公共字母数 #includ ...
- hdu 1195
题意:就是给你n组的四位数,在一次变化中又一位数字可以变化,而变化的方式为加一减一或者是与隔壁的互换,注意,是每一个数字都可以, 求最少的变化次数到达目标的数字 一看这个就应该知道这是一个bfs的题目 ...
- How to call getClass() from a static method in Java?
刚才在学习Java 使用properties类,遇到这样的错误: Cannot make a static reference to the non-static method getClass() ...
- c#excel的操作例子
class MyData//存储行数据 { public List<string> RowData { get; set; } } static void Main(string[] ar ...
- 7.SpringMVC注解优化
新建controller,每个人都可以建自己的controller,比较方便,不用再在web.xml中进行配置,value的请求地址一定要唯一. 优化: 1.上面示例中spring-annotatio ...