בית Home › חלק Part 1: יסודות Foundations › מפגש Session 4 › תרגול Practice
סקירה Overview הרצאה Lecture מצגת Slides תרגול Practice פתרונות Solutions סיכום Summary מדריך טכני Tech guide כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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 1. מה זה "Python"[1:4]? What is "Python"[1:4]?
2. מה ידפיס הקוד? What does this print? python העתקה Copy
name = "dune"
name.upper()
print (name)
3. מה מחזירה "banana".find("x")? What does "banana".find("x") return?
תרגילים Exercises תרגיל Exercise 1ראשי תיבות Initials
קלטו שם פרטי ושם משפחה (שתי שורות) והדפיסו ראשי תיבות באותיות גדולות עם נקודות, למשל N.L.
Read a first and last name (two lines) and print uppercase initials with dots, e.g. N.L.
איך הפלט אמור להיראות? What should the output look like?
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: התו הראשון: first[0]. First character: first[0].
רמז Hint 2: .upper() על התוצאה..upper() on the result.
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
תרגיל Exercise 2ניקוי שם ספר Clean a book title
קלטו שם ספר שהוקלד ברישול (רווחים בקצוות, אותיות מעורבבות). הדפיסו אותו נקי: בלי רווחים בקצוות, כל מילה באות גדולה.
Read a sloppily typed book title (spaces at the ends, mixed case). Print it clean: no spaces at the ends, each word capitalised.
איך הפלט אמור להיראות? What should the output look like? tHE liTTle PRINCE
The Little Prince
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: .strip() ואז .title()..strip() then .title().
רמז Hint 2: אפשר לשרשר: raw.strip().title(). You can chain: raw.strip().title().
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
תרגיל Exercise 3פלינדרום Palindrome
קלטו מילה והדפיסו True אם היא נקראת אותו דבר משני הכיוונים (בלי להתחשב באותיות גדולות), אחרת False.
Read a word and print True if it reads the same both ways (ignoring case), otherwise False.
איך הפלט אמור להיראות? What should the output look like?
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: w.lower() קודם.w.lower() first.
רמז Hint 2: w == w[::-1] נותן True/False.w == w[::-1] gives True/False.
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
תרגיל Exercise 4סופר תנועות Vowel counter
קלטו משפט באנגלית והדפיסו כמה תנועות (a, e, i, o, u) יש בו, בלי להתחשב באותיות גדולות. בלי לולאות: רק count.
Read an English sentence and print how many vowels (a, e, i, o, u) it has, ignoring case. No loops: just count.
איך הפלט אמור להיראות? What should the output look like? The Little Prince lives on a planet
11
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: s = input().lower()s = input().lower()
רמז Hint 2: s.count("a") + s.count("e") + ...s.count("a") + s.count("e") + ...
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
תרגיל Exercise 5מדף, צעד 4: שורת ספר מיושרת Shelf, step 4: an aligned book row פרויקט מלווה Companion project
קלטו שם ספר (מלוכלך) ומספר עמודים. נקו את השם (strip + title) והדפיסו שורה אחת: השם מיושר לשמאל ברוחב 20, |, ומספר העמודים מיושר לימין ברוחב 5.
Read a (messy) book title and a page count. Clean the title (strip + title) and print one row: the title left-aligned in 20 characters, |, and the pages right-aligned in 5.
איך הפלט אמור להיראות? What should the output look like?
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: title = input().strip().title()title = input().strip().title()
רמז Hint 2: f"{title:<20}|{pages:>5}"f"{title:<20}|{pages:>5}"
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
אתגרים לחזקים Challenges for the brave אתגר Challenge 1הסתרת אימייל Mask an email
קלטו כתובת אימייל והדפיסו אותה מוסתרת: התו הראשון, אחריו ***, ואז מה-@ והלאה. noa.levi@example.com → n***@example.com.
Read an email and print it masked: the first character, then ***, then from @ onwards. noa.levi@example.com → n***@example.com.
איך הפלט אמור להיראות? What should the output look like? noa.levi@example.com
n***@example.com
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: at = email.find("@")at = email.find("@")
רמז Hint 2: email[0] + "***" + email[at:]email[0] + "***" + email[at:]
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)
אתגר Challenge 2מילים הפוכות Reverse the words
קלטו משפט והדפיסו את המילים בסדר הפוך (לא את האותיות). I love good books → books good love I.
Read a sentence and print its words in reverse order (not the letters). I love good books → books good love I.
איך הפלט אמור להיראות? What should the output look like? I love good books
books good love I
בדיקה Check הרצה Run איפוס Reset
רמז Hint 1: s.split() מחזיר רשימת מילים (נלמד לעומק במפגש 7).s.split() returns a list of words (more in session 7).
רמז Hint 2: " ".join(...) מחבר בחזרה. ו-[::-1] עובד גם על רשימות." ".join(...) joins back. And [::-1] works on lists too.
רמז Hint 0/2
לפתרון Solution פתרון ויזואלי בסימולציה Visual solution (animated)