Kodewick
開始學 →
基礎←→0 / 112

聊天過濾

#038基礎.replace(word, "***")約 3 分鐘

遊戲聊天室要文明一點。寫 clean_chat(message),把 bad_words 裡的每個詞都換成 ***(不管原來幾個字母)。訊息都是小寫的;沒有壞詞就原樣返回。

示例
clean_chat("you noob")→'you ***'
clean_chat("gg, nice game")→'gg, nice game'
main.py
def clean_chat(message):
    bad_words = ["noob", "loser"]
    for word in bad_words:
        # 在這裡寫:把 message 裡的 word 換成 "***"
        pass
    return message
Ctrl + Enter 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。