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?

Codewars 8 kyu Exclamation marks series #2: Remove all exclamation marks from the end of sentence

Posted at

Codewars 8 kyu Exclamation marks series #2: Remove all exclamation marks from the end of sentence

Task

Remove all exclamation marks from the end of sentence.

Verbalization

  1. 最後の文字が!である限り、
  2. 最後の文字を消す

Code

def remove(st):
    while st.endswith("!"):
        st = st[:-1]
    return st

Other example

rstrip = remove all exclamation marks from the end of the string

def remove(st):
    return st.rstrip(“!”)

Reference

もし、!をすべてけしたかったら、

  1. for文で1つづつ文字をとりだす
  2. もし!でなければ、
  3. 文字をつなげる
def remove(st):
    words = ""
    for i in st:
        if i != "!":
            words += i
    return words
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?