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

جواب «Prompt Checker» چالش 5 از جلسه‌ی 13

سؤال

تابع check_prompt(p) بنویس که پرامپت را (کوچک‌شده) بررسی کند و فهرستی از چیزهای کم را برگرداند: اگر "you are" نداشت "role"، اگر هیچ‌کدام از "sentences"، "list"، "table" نداشت "format"، اگر کمتر از 8 کلمه داشت "details". برای هر پرامپت در prompts چاپ کن missing: ['role', 'format', 'details'] یا missing: [].

راهنما

if "you are" not in p: missing.append("role")؛ قالب: if not ("sentences" in p or "list" in p or "table" in p)؛ کلمه‌ها: len(p.split()) < 8.

یک جواب درست

prompts = [
    "Write about cats.",
    "You are a science teacher. Explain in 3 short sentences why cats land on their feet.",
    "You are a chef. Omelette please.",
]

def check_prompt(p):
    p = p.lower()
    missing = []
    if "you are" not in p:
        missing.append("role")
    if not ("sentences" in p or "list" in p or "table" in p):
        missing.append("format")
    if len(p.split()) < 8:
        missing.append("details")
    return missing

for p in prompts:
    print("missing:", check_prompt(p))

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