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

Prompt Checker چالش 4 از جلسه‌ی 62، متوسط

تابع missing_parts(prompt) را کامل کن: متن را کوچک کند (lower) و برای هر بخش در PARTS اگر هیچ‌کدام از کلمه‌های آن بخش در متن نبود، اسم بخش را به لیست جاافتاده‌ها اضافه کند. برنامه سه پرامپت را بررسی می‌کند؛ خروجی باید این باشد:
prompt 1 missing: role, format, example
prompt 2 missing: example
prompt 3 missing: nothing

PARTS = {
    "role": ["you are", "act as"],
    "task": ["explain", "write", "list", "summarise", "make"],
    "format": ["bullet", "table", "numbered", "sentences", "words"],
    "example": ["example", "for instance", "like this"],
}


def missing_parts(prompt):
    text = prompt.lower()
    missing = []
    # for every part: if no word of that part is in text, add the part
    return missing


prompts = [
    "Explain photosynthesis.",
    "You are a biology tutor. Explain photosynthesis in 3 sentences.",
    "You are a biology tutor. Explain photosynthesis as a numbered list. For example: 1. Light hits the leaf.",
]
for i, p in enumerate(prompts, 1):
    gaps = missing_parts(p)
    print(f"prompt {i} missing:", ", ".join(gaps) if gaps else "nothing")

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 62: پرامپت‌نویسی پیشرفته ۱ · چالش بعدی: Fit the Token Budget

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