Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีหาจำนวน Leap Days ทั้งหมดในช่วงปีใน Python

Python Calendar Library มี Function หา Total Leap Days ในช่วงปี: calendar.leapdays(y1, y2) คืน Total Leap Days ใน Years Range range(y1, y2)

ตัวอย่าง

import calendar
print(calendar.leapdays(1995, 2018))

ผลลัพธ์

6

Leap Years ระหว่าง 1995-2017: 1996, 2000, 2004, 2008, 2012, 2016 = 6 ปี