import, your own modules, the standard library, installing packages and virtual environments.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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
מגריל ספריםBook picker
השתמשו ב-random עם seed(1) כדי לבחור ספר אקראי מהרשימה ולהדפיס אותו, ואז הדפיסו את הרשימה מעורבבת (shuffle).
Use random with seed(1) to pick a random book from the list and print it, then print the list shuffled (shuffle).
איך הפלט אמור להיראות?What should the output look like?
פצלו: כתבו (מתוך הקוד, כמו בהרצאה) מודול storage.py עם save ו-load מהמפגש הקודם, ומודול ראשי שמייבא אותו, שומר ספר אחד, טוען ומדפיס Dune by Frank Herbert. בתוך storage הוסיפו בדיקה עצמית ב-if __name__ == "__main__":.
Split: write (from code, as in the lecture) a storage.py module with save and load from last session, and a main module that imports it, saves one book, loads and prints Dune by Frank Herbert. Inside storage add a self-check in if __name__ == "__main__":.
איך הפלט אמור להיראות?What should the output look like?
Dune by Frank Herbert
main.py
רמזHint 1:מחרוזת רב-שורתית עם """ נוחה לכתיבת המודול.A triple-quoted string is handy for writing the module.
רמזHint 2:import storage ואז storage.save(...).import storage then storage.save(...).
כתבו days_until(today, month, day) שמחזירה כמה ימים נשארו ליום ההולדת הבא (אם עבר השנה, בשנה הבאה; אם היום, 0). הדפיסו עבור היום 19/11/2026 ויום הולדת 3/2 ו-19/11.
Write days_until(today, month, day) returning days until the next birthday (next year if it passed; 0 if today). Print it for today 19/11/2026 and birthdays 3/2 and 19/11.
איך הפלט אמור להיראות?What should the output look like?
כתבו make_password(n) שמחזירה סיסמה באורך n מאותיות וספרות בעזרת secrets ו-string, ומוודאת שיש בה לפחות ספרה אחת (מנסה שוב אם לא). הדפיסו את האורך של סיסמה באורך 12 ואם יש בה ספרה.
Write make_password(n) returning an n-character password of letters and digits using secrets and string, guaranteeing at least one digit (retry if not). Print the length of a 12-character password and whether it has a digit.
איך הפלט אמור להיראות?What should the output look like?