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

Score a System Message چالش 6 از جلسه‌ی 38، سخت

یک نمره‌دهنده‌ی پیام سیستم بساز. score_system(text) با low = text.lower():
- اگر "@" در متن بود یا "password" در low، فوراً -1 برگرداند (اطلاعات خصوصی!).
- +1 اگر "you are" در low بود (نقش).
- +1 اگر یکی از کلمه‌های TONES در low بود (لحن).
- +1 اگر "never" یا "do not" در low بود (قانون).
- +1 اگر دست‌کم یک رقم در متن بود (اندازه؛ ch.isdigit()).
خروجی test: 4، 1، 2، -1.

TONES = ["kind", "funny", "calm", "grumpy", "patient", "friendly"]

def score_system(text):
    low = text.lower()
    points = 0
    return points


# ---- test (do not change) ----
print(score_system("You are a calm guide. Never share secrets. Use at most 2 sentences."))
print(score_system("You are a robot."))
print(score_system("Be friendly and do not shout."))
print(score_system("You are kind. My email is kid@example.com"))

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 38: نقش و شخصیت

بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال