0
0

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のif文

Posted at

Pythonのif文の例文について

ifの使い方をパターン別に書いてみました。
複数の関数を用いた例も参考にしました。
条件式の構成で、必要な知識不足を載せています。

発生している問題・エラー


for n in range(2,10):
    for x in range(2,n):
        if n % x == 0:
            print(n,'equals',x,'*',n//x)
            break
    else:
        print(n,'is a prime number')

また、数値を指定して条件でのコードが以下の通りです。

ifと数値の指定パターン

x = 25 //数値を指定する
if x < 0:
    print('negative')
elif x ==0:
    print('zero')
elif x ==10:
    print('ten') 
elif x ==50:
    print('fifty')
elif x ==25:
    print('twenty-five')
else:
    print('positive')
"""elseからの分岐点の条件を定める
   print('条件名')
"""

基礎からの復習ですが、付け加えること

1、リストの文字の指定の表記

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?