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?

問題概要

文字列Sが与えられ、それが"red"、 "blue"、 "green"のいずれかなら"SSS"、 "FFF"、 "MMM"、それ以外なら"Unknown"を出力する。

解法と実装

文字列を受け取って、if文で判定します。

S = input() # 文字列を受け取る

if S == "red": # Sの文字列に合わせて答えを出力する
  print("SSS")
elif S == "blue":
  print("FFF")
elif S == "green":
  print("MMM")
else:
  print("Unknown")

リストを使って判定することもできます。

S = input() # 文字列を受け取る

A = ["red", "blue", "green"] # 入力として受け取る文字列の候補
ANS = ["SSS", "FFF", "MMM"] # 入力に対応する答え

for i in range(3):
  if S == A[i]: # リスト内の文字列と一致するときに、対応する答えを出力する
    print(ANS[i])
    exit() # 出力したらプログラムを終了させる
print("Unknown")
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?