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が与えられる。
この文字列が"coffee"と似ているか、すなわち3・4文字目と5・6文字目がそれぞれ等しいかどうか判定する。

解法と実装

if文でそれぞれ等しいかどうか判定します。

S = input()
if S[2] == S[3] and S[4] == S[5]: # 最初の文字は0文字目なのでインデックスに注意
  print("Yes")
else:
  print("No")

別のif文に分けることもできます。

S = input()
if S[2] != S[3]:
  print("No")
elif S[4] != S[5]:
  print("No")
else:
  print("Yes")
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?