Kodewick
开始学 →
基础←→0 / 100

聊天过滤

#038基础字符串循环约 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 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。