جواب «Step 4: The Audit Report» چالش 4 از جلسهی 72
سؤال
بازبینِ کامل: برای هر پستِ profile["posts"] و خودِ profile["bio"] بررسی کن کدام دستههای RISKY در آن نشانه دارند. برای هر متن یک خط چاپ کن: bio -> identity, location, security answers یا، اگر هیچ نشانهای نداشت، post 3 -> clean. در پایان امتیازِ خطر را چاپ کن: risk score: 5 (تعدادِ کلِ جفتهای متن/دسته که نشانه داشتند) و بعد توصیه: اگر امتیاز ۴ یا بیشتر بود advice: clean up the bio and delete risky posts وگرنه advice: looking good, re-check in 3 months.
راهنما
یک لیستِ items = [("bio", bio)] + [("post " + str(i), p) ...] بساز. برای هر متن، دستههایی که any(w in text for w in words) دارند را جمع کن.
یک جواب درست
profile = {
"bio": "Sara, 16, Tehran. Student at Example High School. Love my cat Pishi!",
"posts": ["My birthday is 14 March!", "New phone, call me: 0912xxxxxxx", "Best day ever with friends"],
}
RISKY = {
"identity": ["birthday", "16", "Tehran"],
"location": ["School", "pool", "home"],
"contact": ["call me", "0912", "@"],
"security answers": ["cat", "first car", "grandma"],
}
items = [("bio", profile["bio"])]
for i, post in enumerate(profile["posts"], 1):
items.append(("post " + str(i), post))
score = 0
for name, text in items:
found = [cat for cat, words in RISKY.items() if any(w in text for w in words)]
score += len(found)
if found:
print(name + " -> " + ", ".join(found))
else:
print(name + " -> clean")
print("risk score:", score)
if score >= 4:
print("advice: clean up the bio and delete risky posts")
else:
print("advice: looking good, re-check in 3 months")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن