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?

回文判定 Python3編

Posted at

回分かどうか判定せよという問題
ループを回して1文字ずつ取り出して等しいか調べ等しくなければNOを出すというロジック。
文字列を逆にする書き方とzip関数を新たに学ぶ。

S = str(input())
reS = S[::-1]

flag = 'YES'
for x, y in zip(S,reS):
    if x != y:
        flag = 'NO'
        break
print(flag)

でも実は、SとreSが同じだったらOKなのである。
たしかに。。。。

S = str(input())
reS = S[::-1]
if S == reS:
    flag = 'YES'
else:
    flag = 'NO'
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?