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

جواب «Add the Rules» چالش 4 از جلسه‌ی 38

سؤال

add_rules(system, rules) به آخر پیام سیستم یک خط Rules: و بعد هر قانون را با شماره در یک خط تازه اضافه کند و نتیجه را برگرداند. خروجی test:
You are a kind teacher.
Rules:
1. Never ask for personal information.
2. Do not write more than 3 sentences.
3. Say "I am not sure" when you do not know.

راهنما

text = system + "\nRules:"، بعد for i in range(len(rules)): و text += "\n" + str(i + 1) + ". " + rules[i].

یک جواب درست

def add_rules(system, rules):
    text = system + "\nRules:"
    for i in range(len(rules)):
        text += "\n" + str(i + 1) + ". " + rules[i]
    return text


# ---- test (do not change) ----
rules = ["Never ask for personal information.",
         "Do not write more than 3 sentences.",
         'Say "I am not sure" when you do not know.']
print(add_rules("You are a kind teacher.", rules))

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