当前位置: 首页 > 网络应用技术

有多少天的python有一年算法?

时间:2023-03-08 20:46:37 网络应用技术

  指南:本文的首席执行官Note将介绍一年中Python的算法数天的相关内容。我希望这对每个人都会有所帮助。让我们来看看。

  x = eval(输入('请输入年度:''))

  如果(x%100 == 0):

  y = x%400

  如果(y == 0):

  打印('366')

  别的:

  打印('365')

  如果(x%100!= 0):

  z = x%4

  如果(z == 0):

  打印('366')

  别的:

  打印('365')

  请采用纯手

  def leap_year_or_not(年):

  #Century Leap年:世纪LEAP年可以删除400。

  #:可以以4的方式删除的那一年,但不能以100的速度删除是普通的leap年。

  #leap年有366天,而另一年只有365天。

  如果INT(YEAR)%400 == 0:

  返回true

  elif int(年)%100!= 0和int(年)%4 == 0:

  返回true

  别的:

  返回false

  def calculate_days_of_year(年):

  leap = leap_year_or_not(年)

  如果leap:

  天= 366

  run =“ is”

  别的:

  天= 365

  run =“否”

  print(“ {}年{} leap年,有{}天。”格式(年,运行,天))

  如果__name__ ==“ __ -main __”:

  打印(“输入年:”)

  n = init()

  calculate_days_of_year(n)

  运行上述代码,输入2019 Enter,获取以下结果:

  导入日期

  导入日历

  年= int

  月= int(int('请输入1至12个月:')#

  day = int(输入('请输入每日部分1至31:'))#获取“天”

  if(calendar.isleap(年)== true):

  印刷(“ leap Years”)

  别的:

  印刷(“ ping年”)

  如果(月== 1或月== 3或月== 5或月== 7或月== 8或月== 10或月== 12):

  印刷('31天')

  elif(月== 4或月== 6或月== 9或月== 11):

  印刷('30天')

  elif月== 2和((年%4 == 0和年%100!= 0)或(年%400 == 0):

  印刷(“ 29天”)

  别的:

  印刷(“ 28天”)

  targetDay = dateTime.date(年,月,天)#将输入日期格式化为标准日期

  daycount = targetday -dateTime.date(targetday.year -1,12,31)#减去上一年的最后一天

  print('%s是%s的天数。'%(目标,年,daycount.day)

  结论:以上是首席CTO的全部内容指出,关于Python的Python年度算法有多少天。我希望这对每个人都会有所帮助。如果您仍然想了解有关此信息的更多信息,请记住收集并关注此网站。