2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Python】うるう年を判定する

Last updated at Posted at 2019-11-12

#初学者が押さえるべきポイントが網羅

初学者が書くプログラムとして
3の倍数、5の倍数を出力するfizzbuzz問題をよく見かけますが、
if文、変数、比較演算子、型など初学者がまず学ぶのに
より実践的・実用的なプログラムとして、うるう年の判定はぴったりだと思います。

leap.py
year_str = input("西暦4桁を入力")
year = int(year_str)

if year % 100 == 0 and year % 400 != 0:
    print("平年です")
elif year % 4 == 0:
    print("うるう年です")
else:
    print("平年です")

あとPythonはインデントに要注意ですね。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?