程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How does python determine whether it is a leap year? There are 366 days in a leap year, and one extra day in February is 29 days

編輯:Python

How does python determine whether it is a leap year

def isRunYear(year):
if (year % 100 == 0 and year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
return True
else:
return False

year, month, day = map(int, input().split())
    
dic = {}
dic[1] = 31
dic[3] = 31
dic[5] = 31
dic[7] = 31
dic[8] = 31
dic[10] = 31
dic[12] = 31
dic[4] = 30
dic[6] = 30
dic[9] = 30
dic[11] = 30

if isRunYear(year):
    dic[2] = 29
else:
    dic[2] = 28
    
ans = 0
for i in range(1,month):
ans += dic[i]
ans += day
print(ans)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved