0
1

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 3 years have passed since last update.

pythonで入力した値の約数を調べる

Last updated at Posted at 2020-08-24

#はじめに
約数を求めるプログラムコードのメモとしての記述です。

##プログラムコード

div = []
num = int(input())
if num >= 2:
    for j in range(num):
        if num % (j + 1) == 0:
            div.append(j + 1)
    else:
        print(div)

###簡単な説明
入力した値をfor文のループ処理で割っていき、割った時のあまりが0の場合のみを配列に追加している。最後に配列を出力する。

##実行結果

入力値
28

出力値
[1, 2, 4, 7, 14, 28]
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?