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

The App Skeleton چالش 6 از جلسه‌ی 46، سخت

اسکلت هر سه مسیر یک «مسیریاب» پیام است. handle(message):
- /help → HELP.
- اگر با /ask شروع شد: باقی متن (message[5:]) را با ask بپرس و جواب را برگردان؛ اگر باقی متن خالی بود (/ask تنها) → Type a question after /ask.
- /quiz → سؤال بعدی QUIZ به نوبت (بعد از آخری دوباره از اول)، با یک شمارنده‌ی global quiz_index.
- هر چیز دیگر → I don't understand. Type /help.
خروجی test با HELP شروع می‌شود، بعد (model) why is the sky blue، بعد سه سؤال کوییز (Q1، Q2، دوباره Q1).

from ai import ask

HELP = "Commands: /help, /ask <question>, /quiz"
QUIZ = ["Q1: How many moons does Nilu have?", "Q2: When does Sprout water the beds?"]
quiz_index = 0

def handle(message):
    return HELP


# ---- test with a pretend model (do not change) ----
def fake_ask(prompt, system=None, history=None):
    return "(model) " + prompt
ask = fake_ask

for message in ["/help", "/ask why is the sky blue", "/quiz", "/quiz", "/quiz", "/ask", "hello"]:
    print(handle(message))

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 46: پروژه‌ی نهایی ۱: نقشه

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