编写Python程序使用循环语句输出1990到2040年间所有的闰年要求每行输出5个年份
# 判断闰年的函数
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
# 循环输出闰年
count = 0
for year in range(1990, 2041):
if is_leap_year(year):
print(year, end=' ')
count += 1
if count == 5:
print()
count = 0
输出结果为:
1992 1996 2000 2004 2008
2012 2016 2020 2024 2028
2032 2036 2040
原文地址: https://www.cveoy.top/t/topic/bIQm 著作权归作者所有。请勿转载和采集!