1.输入日期,判断日期是该年度的第几天

  

iyear = int(input("请输入年:\n"))
imonth = int(input("请输入月:\n"))
iday = int(input("请输入日:\n")) def checkYear(iyear):
return ((iyear % 4 == 0 and iyear % 100 != 0) or iyear % 400 == 0) tol_day = 0 for i in range(1, imonth):
# tol_day+=lis[i]
if i in [1, 3, 5, 7, 8, 10, 12]:
tol_day += 31
elif i == 2:
tol_day += 28
if checkYear(iyear):
tol_day += 1
else:
tol_day += 30
tol_day += iday
print(tol_day) 或者:
lis = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#如果是闰年的话,2月份加一天
if checkYear(year):
lis[2] += 1
#遍历一次days,对应月份中的天数,把对应的天数传递给tol_day存储
for i in range(month):
tol_day+= lis[i]
print(tol_day+iday)

2..输入日期,判断日期距离现在是多少天

#datetime 获取年月日
import datetime
datetime.datetime.now().year
datetime.datetime.now().month
datetime.datetime.now().day import datetime def func():
y = input("请输入年份")
m = input("请输入月份")
d = input("请输入日期")
t1 = datetime.datetime.now()#获取当前时间
t2 = datetime.datetime(int(y),int(m),int(d))#获取指定时间
t3 = t2 - t1
print("离%s-%s-%s还有%d天"%(y,m,d,t3.days))
func()

 3.打印以下内容:

for i in range(9, 0, -1):
for k in range(0, 9 - i):
print(" ", end="\t")
for j in range(1, i + 1):
print("{}*{}={:02d}".format(i, j, i * j), end="\t")
print() for i in range(1, 11):
for j in range(1, 11):
print(" * ", end="") print() print("---------------------------")
for i in range(1, 11):
for j in range(1, 11):
if i == 1 or i == 10:
print(" * * * * * * * * * * ", end="")
break
elif j == 1 or j == 10 :
print(" * ", end="")
else:
print(" . ", end="")
print() print("---------------------") for i in range(1, 11):
for j in range(1, 11):
if i == 1 or i == 10:
print(" * * * * * * * * * * ", end="")
break
elif i == j or j == 1 or j == 10 or (i + j == 11):
print(" * ", end="")
else:
print(" ", end="")
print() print("---------------------") for i in range(1, 11):
for j in range(1, 11):
if i == 1 or i == 10:
print(" * * * * * * * * * * ", end="")
break
elif i == j or j == 1 or j == 10 or (i + j == 11):
print(" * ", end="")
elif i <= j and j + i >= 11:
print(" $ ", end="")
else:
print(" ", end="")
print()

  

python判断输入日期是该年的第几天的更多相关文章

  1. C#字符串截取、获取当前电脑时间、判断输入日期对错 随手记

    字符串截取:这个就当复习了,看意见就可以 //身份证生日截取 //Console.WriteLine("请输入18位身份证号:"); //string x = Console.Re ...

  2. Javascript Date 判断输入日期是否正确

    JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date ...

  3. PHP 关于判断输入日期是否合法

    合法要求 一年仅十二个月 4,6,9,11月仅30天,1,3,5,7,8,10,12月仅31天 闰年2月29天,否则28天 输入的变量年,月,日为数字 代码: <?php //PHP中判断输入的 ...

  4. Python判断输入字符类型

    """从键盘上输入 一个字符,判断其字符类型.""" while True: char = input("请输入需要判断的字符:& ...

  5. day1 python判断输入的密码是否正确

    _username = 'leon' _password = 'zyl' username = input("username:") password = input(" ...

  6. C#正则表达式判断输入日期格式是否正确

      /// <summary>        /// 是否为日期型字符串        /// </summary>        /// <param name=&qu ...

  7. Python中判断是否为闰年,求输入日期是该年第几天

    #coding = utf-8 def getLastDay(): y = int(input("Please input year :")) m = int(input(&quo ...

  8. C++判断输入是否为double

    C++判断输入是否为double 之前写过了Python如何判断输入字符串是否为数字,但是Python是弱类型语言,相比之下C++这种强类型语言判定难度更大. Python判断输入字符串是否为数字的方 ...

  9. python中输入某年某月某日,判断这一天是这一年的第几天?

    输入某年某月某日,判断这一天是这一年的第几天?程序分析 特殊情况,闰年时需考虑二月多加一天: 直接上代码 #定义一个函数,判断是否为闰年 def leapyear(y): return (y % 40 ...

随机推荐

  1. Quick BI 的模型设计与生成SQL原理剖析

    一.摘要 随着物联网的告诉发展,数据量呈现井喷式的增长,如何来分析和使用这些数据,使数据产生商业价值,已经变得越来越重要.值得高兴的是,当前越来越多的人已经意识到了用数据分析决定商业策略的重要性,也都 ...

  2. LOJ#3119 随机立方体

    解:极大值至少为1.我们尝试把最大那个数的影响去掉. 最大那个数所在的一层(指一个三维十字架)都是不可能成为最大值的. 考虑容斥.我们试图求除了最大值以外至少有k个极大值的概率. 我们钦定某k个位置是 ...

  3. 88 Lowest Common Ancestor of a Binary Tree

    原题网址:https://www.lintcode.com/problem/lowest-common-ancestor-of-a-binary-tree/description 描述 给定一棵二叉树 ...

  4. MySQL数据库基本使用

    一 .数据库概述 数据库就是以一定格式进行组织的数据的集合.通俗来看数据库就是用户计算机上 一些具有特殊格式的数据文件的集合. 数据库也可以理解为表格,大家都知道表格都是由表名.表头.数据等几部分组成 ...

  5. redis学习笔记04-事务

    1.redis事务 事务实际上指的是一组命令的集合,执行时会按顺序串行的执行,中途不能加入其它命令.它用来解决批处理需求. 在redis中的基本使用如下: >multi ok >incr ...

  6. spring boot项目启动报DataSource错误

    初建一个简单的spring boot 项目,启动后会报错. Exception encountered during context initialization - cancelling refre ...

  7. linux下用eclipse开发mapreduce遇到的问题

    Unable to create the selected preference page.org/apache/hadoop/eclipse/preferences/MapReducePrefere ...

  8. Leetcode147. Insertion Sort List对链表进行插入排序

    对链表进行插入排序. 从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示). 每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中. 插入排序算法: 插入排序是 ...

  9. angular1.0 $http jsonp callback

    $http.jsonp(sDUrl,{cache:false,jsonpCallbackParam:'callback'}); https://stackoverflow.com/questions/ ...

  10. uni-app开发的应用(小程序,app,web等),使用Node+Koa2开发的后端程序接收上传文件的方法

    uni-app使用使用Node+Koa2开发的后端程序接收上传的文件 通过gitbook浏览此随笔 通过其它客户端上传(h5,小程序等),接收方法一致 使用koa接收时,我们需安装一个中间件koa-b ...