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

Naive Join چالش 2 از جلسه‌ی 27، آسان

تابع read_naive را کامل کن تا BASE + name را در دیکشنری files جست‌وجو کند و اگر نبود "not found" برگرداند. خروجی باید دو خط باشد: buy milk و 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):
    # look up BASE + name; "not found" if missing
    return ""


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

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 27: مسیر فایل و `..` · چالش بعدی: Normalise

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