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

The Biggest Risks First چالش 5 از جلسه‌ی 46، سخت

هر خطر یک تاپل است: (name, chance, harm, control) با chance و harm از ۱ تا ۳. top_risks(risks, n) خطرها را از بیشترین chance * harm به کمترین چاپ کند (برابرها به ترتیب لیست) و فقط n تای اول را: 9 prompt injection -> spot attacks, fence the text, check the output. بدون sort: امتیاز را از 9 تا 1 پایین بیا و در هر امتیاز خطرهای همان امتیاز را چاپ کن. خروجی test:
9 prompt injection -> spot attacks, fence the text, check the output
6 it makes up answers -> answer only from the handout and show the source
6 someone types their phone number -> warn users and never save the chat

def top_risks(risks, n):
    for name, chance, harm, control in risks[:n]:
        print(chance * harm, name, "->", control)


# ---- test (do not change) ----
risks = [
    ("it makes up answers", 3, 2, "answer only from the handout and show the source"),
    ("someone types their phone number", 2, 3, "warn users and never save the chat"),
    ("the relay is off", 2, 1, "use a ready answer"),
    ("prompt injection", 3, 3, "spot attacks, fence the text, check the output"),
    ("it is too slow", 1, 1, "keep the prompt short"),
]
top_risks(risks, 3)

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

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