输出2020年以后出现的第一个闰年
这个是用for i in range 吗
可以的,老铁,望采纳
代码:
for year in range(2020, 10000):
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print(year)
break
# Python程序检查是否为闰年
def leapyr(n):
# 如果n能被4整除,但不能被100整除,或者n能被400整除
if (n % 4 == 0 and n % 100 != 0) or (n % 400 == 0):
# 返回True表示是闰年
return True
else:
# 返回False表示不是闰年
return False
# 从2020年开始循环
year = 2020
# 当没有找到闰年时继续循环
while not leapyr(year):
# 年份加一
year += 1
# 打印第一个闰年
print(year, "是2020年以后出现的第一个闰年。")
详细解释,有帮助希望采纳
不知道你这个问题是否已经解决, 如果还没有解决的话: