נבנה על ידיBuilt by Ariel Yohimovich

PythonPython
4
חלקPart 1: יסודותFoundations כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

מחרוזותStrings

אינדקסים, חיתוך, מתודות של מחרוזות ועיצוב פלט.

Indexing, slicing, string methods and formatting output.

כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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
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?
noa
levi
N.L.
main.py
רמזHint 1: התו הראשון: first[0].First character: first[0].
רמזHint 2: .upper() על התוצאה..upper() on the result.
לפתרוןSolution
תרגיל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
main.py
רמזHint 1: .strip() ואז .title()..strip() then .title().
רמזHint 2: אפשר לשרשר: raw.strip().title().You can chain: raw.strip().title().
לפתרוןSolution
תרגיל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?
Racecar
True
main.py
רמזHint 1: w.lower() קודם.w.lower() first.
רמזHint 2: w == w[::-1] נותן True/False.w == w[::-1] gives True/False.
לפתרוןSolution
תרגיל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
main.py
רמזHint 1: s = input().lower()s = input().lower()
רמזHint 2: s.count("a") + s.count("e") + ...s.count("a") + s.count("e") + ...
לפתרוןSolution
תרגיל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?
  dune 
412
Dune                |  412
shelf.py
רמזHint 1: title = input().strip().title()title = input().strip().title()
רמזHint 2: f"{title:<20}|{pages:>5}"f"{title:<20}|{pages:>5}"
לפתרוןSolution

אתגרים לחזקים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
main.py
רמזHint 1: at = email.find("@")at = email.find("@")
רמזHint 2: email[0] + "***" + email[at:]email[0] + "***" + email[at:]
לפתרוןSolution
אתגר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
main.py
רמז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.
לפתרוןSolution

נבנה על ידיBuilt by Ariel Yohimovich