جواب «Prompt Checker» چالش 4 از جلسهی 62
سؤال
تابع missing_parts(prompt) را کامل کن: متن را کوچک کند (lower) و برای هر بخش در PARTS اگر هیچکدام از کلمههای آن بخش در متن نبود، اسم بخش را به لیست جاافتادهها اضافه کند. برنامه سه پرامپت را بررسی میکند؛ خروجی باید این باشد:prompt 1 missing: role, format, exampleprompt 2 missing: exampleprompt 3 missing: nothing
راهنما
for part, words in PARTS.items(): و بعد found = any(w in text for w in words)؛ اگر not found بود missing.append(part).
یک جواب درست
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 part, words in PARTS.items():
found = False
for w in words:
if w in text:
found = True
if not found:
missing.append(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")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن