编写主程序,输入一个年份,输出从这个年份开始的10个闰年。
主程序的公式是什么?设计思路是什么呢?
def isleap(m):
if (m%4 == 0 and m%100!=0) or m%400 == 0:
return True
return False
count = 0
m = int(input())
while count<10:
if isleap(m):
print(m)
count += 1
m+=1
主程序就是判断和and or的搭配使用。
思路:先是一个可以return true false 的函数,这个用来判断是不是闰年,然后获取输入的年份。对这个年份进行+1 的while循环,同时用另一个变量记录得到的闰年数量,到10就停止循环
def isLeap(y):
if (y%4==0 and y%100!=0) or y%400==0:
return True
else:
return False
start = int(input('请输入起始年份:'))
num = 0
while num<10:
if isLeap(start):
num += 1
print(start, end=' ')
start +=1