Pythonコード実装サイクル入力年が閏年であるか否かを判断し、入力回数をカスタマイズする
Pythonコード実装サイクル入力年が閏年であるか否かを判断し、入力回数をカスタマイズする
出力結果:
# , 4 100 , 400
def leap_year(temp):
if (temp % 4) == 0:
if (temp % 100) != 0:
print('%d !' % temp)
else:
if (temp % 400) == 0:
print('%d !' % temp)
else:
print('%d ^-^' % temp)
else:
print('%d ^-^' % temp)
for i in range(20):
temp = input(" :")
temp = int(temp)
leap_year(temp)
出力結果:
=================== RESTART: F:\python-exercises\leap_year.py ==================
:2020
2020 !
:2123
2123 ^-^
:2224
2224 !
:2352
2352 !
:2000
2000 !
:2323
2323 ^-^
:646
646 ^-^
:54
54 ^-^
:254
254 ^-^
:5
5 ^-^
: