כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-VS Code. ההתקדמות נשמרת.Write in each exercise's editor, press Run to see output and Check for the automatic checker. You can also work in VS Code. Progress is saved.
חימום: 3 שאלותWarm-up: 3 questions
תרגיליםExercises
תרגילExercise 1
המאגר הראשון שלכםYour first repo
נבדק ידניתSelf-checked
על המחשב שלכם: התקינו Git, הגדירו שם ומייל, צרו תיקייה hello-git עם קובץ hello.py, ובצעו שני commits: אחד שיוצר את הקובץ ואחד שמשנה אותו. בסוף git log --oneline צריך להראות שתי שורות.
On your computer: install Git, set name and email, create a folder hello-git with hello.py, and make two commits: one creating the file and one changing it. At the end git log --oneline should show two lines.
כתבו ignored(path, patterns) שמחזירה True אם הנתיב תואם לאחת התבניות. תבנית שמסתיימת ב-/ היא תיקייה (מתאימה אם הנתיב מתחיל בה או מכיל אותה), ושאר התבניות נבדקות מול שם הקובץ עם fnmatch. ואז to_commit(paths, patterns) מחזירה את מה שלא מתעלמים ממנו.
Write ignored(path, patterns) returning True if the path matches a pattern. A pattern ending in / is a folder (matches if the path starts with it or contains it); others are checked against the file name with fnmatch. Then to_commit(paths, patterns) returns the paths not ignored.
איך הפלט אמור להיראות?What should the output look like?
['shelf.py', 'README.md']
main.py
רמזHint 1:from fnmatch import fnmatch ו-path.split("/")[-1] לשם הקובץ.from fnmatch import fnmatch and path.split("/")[-1] for the name.
רמזHint 2:תיקייה: path.startswith(p) or "/" + p in "/" + path.Folder: path.startswith(p) or "/" + p in "/" + path.
פלט של git log --oneline נתון כמחרוזת. כתבו parse_log(text) שמחזירה רשימת זוגות (hash, message), ו-bad_messages(commits) שמחזירה hashes של הודעות קצרות מ-10 תווים או שהן אחת המילים fix, wip, stuff (בלי רגישות לאותיות).
git log --oneline output is given as a string. Write parse_log(text) returning a list of (hash, message) pairs, and bad_messages(commits) returning hashes of messages shorter than 10 characters or equal to fix, wip, stuff (case-insensitive).
איך הפלט אמור להיראות?What should the output look like?
5 ['9f8e7d6', '0d1e2f3', '77aa88b']
main.py
רמזHint 1:line.split(" ", 1) מחלק פעם אחת בלבד.line.split(" ", 1) splits only once.
כתבו check_message(msg) שמחזירה רשימת בעיות (רשימה ריקה = הודעה טובה): "empty" אם ריקה, "too long" אם השורה הראשונה מעל 50 תווים, "capital" אם לא מתחילה באות גדולה, "period" אם השורה הראשונה מסתיימת בנקודה.
Write check_message(msg) returning a list of problems (empty list = a good message): "empty" if empty, "too long" if the first line exceeds 50 characters, "capital" if it doesn't start with a capital letter, "period" if the first line ends with a period.
איך הפלט אמור להיראות?What should the output look like?
מדף, צעד 20: הפרויקט ב-GitHubShelf, step 20: the project on GitHub
פרויקט מלווהCompanion projectנבדק ידניתSelf-checked
על המחשב שלכם: בתיקיית פרויקט המדף צרו .gitignore (עם .venv/, __pycache__/, .env), git init, commit ראשון של כל הקבצים, צרו repo ב-GitHub, חברו עם git remote add origin ו-git push -u origin main. בדקו בדפדפן שהקבצים שם ושאין שם .venv.
On your computer: in the shelf project folder create .gitignore (with .venv/, __pycache__/, .env), git init, a first commit of all files, create a repo on GitHub, connect with git remote add origin and git push -u origin main. Check in the browser that the files are there and .venv isn't.
רמזHint 1:git add . מוסיף הכול חוץ ממה שב-.gitignore.git add . adds everything except what's in .gitignore.
רמזHint 2:ב-VS Code: Source Control → Publish to GitHub עושה את כל השלבים בלחיצה.In VS Code: Source Control → Publish to GitHub does all the steps in one click.
git status --porcelain מחזיר שורות כמו M shelf.py, M app.py, ?? notes.txt, A new.py, D old.py. שני התווים הראשונים: מצב ב-staging ומצב בתיקייה. כתבו summarize(text) שמחזירה מילון עם הרשימות staged, modified, untracked (קובץ יכול להופיע גם ב-staged וגם ב-modified, למשל MM).
git status --porcelain returns lines like M shelf.py, M app.py, ?? notes.txt, A new.py, D old.py. The first two characters: staging state and folder state. Write summarize(text) returning a dict with lists staged, modified, untracked (a file can be both staged and modified, e.g. MM).
איך הפלט אמור להיראות?What should the output look like?
רמזHint 1:x, y, path = line[0], line[1], line[3:]x, y, path = line[0], line[1], line[3:]
רמזHint 2:?? = untracked. אחרת: x שאינו רווח = staged, y שאינו רווח = modified.?? = untracked. Otherwise: non-space x = staged, non-space y = modified.
כתבו mini_diff(old, new) שמקבלת שתי מחרוזות רב-שורתיות ומחזירה רק את שורות השינוי בפורמט של git: -שורה לשורה שהוסרה ו-+שורה לשורה שנוספה. השתמשו ב-difflib.ndiff ושמרו רק שורות שמתחילות ב-- או + .
Write mini_diff(old, new) taking two multi-line strings and returning only the change lines in git style: -line for removed and +line for added. Use difflib.ndiff and keep only lines starting with - or + .
איך הפלט אמור להיראות?What should the output look like?
-shelf = ["Dune", "Emma"]
+shelf = ["Dune", "Emma", "Matilda"]
-for b in shelf:
+for b in sorted(shelf):