x = int(input())
def leap_year(year):
result = []
for i in range(1, year + 1):
if i % 4 == 0 and (i % 100 != 0 or i % 400 == 0):
result.append(str(i))
return result
print(' '.join(leap_year(x)))
以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:
思路:
示例代码:
def leap_year(x):
result = []
for year in range(1, x+1):
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
result.append(year)
return result
# 测试
print(leap_year(2022)) # [4, 8, 12, ..., 2016, 2020]