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

جواب «Naive Join» چالش 2 از جلسه‌ی 27

سؤال

تابع read_naive را کامل کن تا BASE + name را در دیکشنری files جست‌وجو کند و اگر نبود "not found" برگرداند. خروجی باید دو خط باشد: buy milk و not found.

راهنما

return files.get(BASE + name, "not found").

یک جواب درست

files = {
    "/home/user/notes.txt": "buy milk",
    "/home/user/todo.txt": "finish homework",
    "/home/secret.txt": "admin password: hunter2",
}
BASE = "/home/user/"


def read_naive(name):
    return files.get(BASE + name, "not found")


print(read_naive("notes.txt"))
print(read_naive("../secret.txt"))

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