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?

Pythonで「if文を使った条件分岐」の動作を確認してみた

Posted at

概要

Pythonで「if文を使った条件分岐」の動作を確認してみました。以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
old = 18
print("年齢は" + str(old) + "です。")
if old < 20:
    print("20歳未満の方はご利用できません。")
    print("またのご利用をお待ちしています。")
    
print("ありがとうございました。")

old = 24
print("年齢は" + str(old) + "です。")
if old < 20:
    print("20歳未満の方はご利用できません。")
    print("またのご利用をお待ちしています。")

print("ありがとうございました。")

old = 18
print("年齢は" + str(old) + "です。")
if old < 20:
    print("20歳未満の方はご利用できません。")
    print("またのご利用をお待ちしています。")
else:
    print("ご利用ありがとうございます。開始ボタンを押してください。")

old = 24
print("年齢は" + str(old) + "です。")
if old < 20:
    print("20歳未満の方はご利用できません。")
    print("またのご利用をお待ちしています。")
else:
    print("ご利用ありがとうございます。開始ボタンを押してください。")

postcode = "125-0062"
print("郵便番号は " + postcode + " です。")
if postcode == "140-0015":
    address = "東京都品川区西大井"
elif postcode == "102-0072":
    address = "東京都千代田区飯田橋"
elif postcode == "125-0062":
    address = "東京都葛飾区青戸"
else:
    address = "不明"

print("住所は " + address + " です。")

postcode = "102-0072"
print("郵便番号は " + postcode + " です。")
if postcode == "140-0015":
    address = "東京都品川区西大井"
elif postcode == "102-0072":
    address = "東京都千代田区飯田橋"
elif postcode == "125-0062":
    address = "東京都葛飾区青戸"
else:
    address = "不明"

print("住所は " + address + " です。")

以下のコマンドを実行しました。

$ python3 sample.py 
年齢は18です。
20歳未満の方はご利用できません。
またのご利用をお待ちしています。
ありがとうございました。
年齢は24です。
ありがとうございました。
年齢は18です。
20歳未満の方はご利用できません。
またのご利用をお待ちしています。
年齢は24です。
ご利用ありがとうございます。開始ボタンを押してください。
郵便番号は 125-0062 です。
住所は 東京都葛飾区青戸 です。
郵便番号は 102-0072 です。
住所は 東京都千代田区飯田橋 です。

まとめ

何かの役に立てばと。

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?