2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【python3】三項演算子を使った条件式

Last updated at Posted at 2025-08-31

はじめに

三項演算子を使った条件式を使って以下の問題を解きました。

問題

あなたは外出時する時に気温が一定を超えたら熱中症に注意しようと考えています。
気温 t が与えられるので 30 度以上の場合は "DANGER" と出力し 30 度未満の場合は気温 t をそのまま出力してください。

実装したコード

# coding: utf-8
# 自分の得意な言語で
# Let's チャレンジ!!
t = int(input())
print("DANGER") if t >= 30 else print(t)

実行結果

実行結果は以下の通り

aaaaa.jpg

最後に

三項演算子を使ってみました

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?