بتل کد Battle Codeدارد باز می‌شود…

جواب «Keep It Private» چالش 8 از جلسه‌ی 17

سؤال

یک ربات محتاط: اگر در پیام (با حروف کوچک) یکی از کلمه‌های password، address یا phone بود بگوید Please do not send me personal information.؛ اگر پیام فقط رقم بود و ۱۰ رقم یا بیشتر داشت بگوید That looks like a phone number. Please keep it private.؛ وگرنه Thanks for your message!.

راهنما

با for word in private_words: و if word in text.lower(): بگرد. برای شماره: text.isdigit() and len(text) >= 10.

یک جواب درست

import bot

private_words = ["password", "address", "phone"]


def reply(text):
    for word in private_words:
        if word in text.lower():
            return "Please do not send me personal information."
    if text.isdigit() and len(text) >= 10:
        return "That looks like a phone number. Please keep it private."
    return "Thanks for your message!"


bot.run(reply)

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن