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?

⑥if/ifの考え方を日常生活のイベントに当てはめてみた!

0
Posted at

⚙️ Introduction

if/ifが大事だと思い、掲載することにしました。
if/for, for/if の応用としてもそのまま使えます。

🏠 ①「雨が降っている → しかも強い雨なら → 傘+レインコートを持つ」

日常の流れ
  • 雨が降っている(if
  • しかも強い雨なら(if

傘+レインコートを持つ

rain.py
is_raining = True
is_heavy_rain = True

if is_raining:                          # まず雨かどうか
    if is_heavy_rain:                   # その中で強い雨かどうか
        print("傘とレインコートを持っていく")

🍱 ②「お腹が空いている → しかも時間があるなら → 自炊する」

日常の流れ
  • お腹が空いている(if
  • しかも時間がある(if

自炊する

cook.py
hungry = True
have_time = True

if hungry:                              # お腹が空いてる
    if have_time:                       # 時間がある
        print("自炊する")

🚉 ③「電車が遅延している → しかも10分以上なら → 迂回ルートを使う」

日常の流れ
  • 遅延している(if
  • しかも10分以上(if

迂回ルートへ

train_delay.py
delayed = True
delay_minutes = 12

if delayed:                              # 遅延している
    if delay_minutes >= 10:              # 10分以上
        print("迂回ルートを使う")

🧺 ④「部屋が汚れている → しかも床が汚れているなら → 掃除機をかける」

日常の流れ
  • 部屋が汚れている(if
  • しかも床が汚れている(if

掃除機をかける

clean.py
room_dirty = True
floor_dirty = True

if room_dirty:                           # 部屋が汚い
    if floor_dirty:                      # 床が汚い
        print("掃除機をかける")

🎮 ⑤「ゲーム中 → しかもボス戦なら → 特別スキルを使う」

日常の流れ
  • ゲーム中(if
  • しかもボス戦(if

特別スキル発動

game_start.py
game_started = True
boss_fight = True

if game_started:                         # ゲーム中
    if boss_fight:                       # ボス戦
        print("特別スキル発動!")

🎯 Conclusion

ifif は “状況の中でさらに状況を判定する” という構造になっており、日常生活に自然に存在している。

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?