用函数判断是否为闰年,以及闰年的个数!

编写一个程序,在主程序中求1990-2020年中的所有闰年,每行输入五个年份,闰年即能被四4整除但不能被100整除,或者能被四十整除的年份,要求定义一个函数isLeap(),该函数用来判断某年是否为闰年,是闰年则高数返回True,否则返回False!

源程序如下:

def isLeapYear(year):
    if (year % 4) == 0 and (year % 100) != 0 or (year % 400) == 0:
        return True
    else:
        return False            
            
count = 0
leapYear=[]
for i in list(range(1990,2020,1)):
    if isLeapYear(i):
        count += 1
        leapYear.append(i)
print("闰年个数有 %d 个:"%count)
print("这%d个闰年分别是:"%count)
print(leapYear)

运行结果如下:

闰年个数有 7 个:
这7个闰年分别是:
[1992, 1996, 2000, 2004, 2008, 2012, 2016]

 

a = 0
m=int(input('请输入起始年份:\n'))
n=int(input('请输入结束年份:\n'))
for i in range(m,n):
    if i%4==0 and i%100!=0 or i%100==0:
        a = a + 1
        print('闰年为:',str(i))
print('闰年数量:',a)