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

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

מילונים, טאפלים וסטיםDicts, tuples & sets

מפתח-ערך, טאפלים בלתי משתנים, סטים בלי כפילויות.

Key-value pairs, immutable tuples, sets without duplicates.

נסו לפתור לבד לפני שמציצים. בנגן: חיצים במקלדת או הכפתורים. כל צעד מראה איפה (קובץ ושורה), מה כותבים ולמה.Try on your own before peeking. In the player use the arrow keys or the buttons. Each step shows where (file and line), what to write, and why.
תרגילExercise 1

מחירוןPrice list

תזכורת: מה ביקשוReminder: the task

נתון מילון מחירים. קלטו שם מוצר והדפיסו את המחיר שלו, או not found אם אין כזה.

Given a price dict, read a product name and print its price, or not found if missing.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
prices = {"milk": 6.9, "bread": 8, "eggs": 12.5}
item = input().strip()
print(prices.get(item, "not found"))
פלטOutput
eggs
12.5

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 2

ספירת מיליםWord count

תזכורת: מה ביקשוReminder: the task

קלטו משפט (באותיות קטנות) והדפיסו כמה פעמים מופיעה כל מילה, בסדר ההופעה הראשונה, בפורמט word: n.

Read a sentence (lowercase) and print how many times each word appears, in first-appearance order, as word: n.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
counts = {}
for w in input().split():
    counts[w] = counts.get(w, 0) + 1
for w, n in counts.items():
    print(f"{w}: {n}")
פלטOutput
the cat the dog and the cat
the: 3
cat: 2
dog: 1
and: 1

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 3

מרחק בין נקודותDistance between points

תזכורת: מה ביקשוReminder: the task

נתונים שני טאפלים a = (1, 2) ו-b = (4, 6). פרקו אותם למשתנים והדפיסו את המרחק ביניהם (פיתגורס).

Given two tuples a = (1, 2) and b = (4, 6), unpack them and print the distance between them (Pythagoras).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
a = (1, 2)
b = (4, 6)
x1, y1 = a
x2, y2 = b
print(((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5)
פלטOutput
5.0

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 4

חברים משותפיםBooks in common

תזכורת: מה ביקשוReminder: the task

נתונים שני סטים של ספרים שקראו נועה ודן. הדפיסו (ממוינים) את הספרים ששניהם קראו, ואחר כך את אלה שרק נועה קראה.

Given two sets of books Noa and Dan read, print (sorted) the books both read, then those only Noa read.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
noa = {"Dune", "Emma", "Matilda", "Ulysses"}
dan = {"Dune", "Ulysses", "Beloved"}
print(sorted(noa & dan))
print(sorted(noa - dan))
פלטOutput
['Dune', 'Ulysses']
['Emma', 'Matilda']

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

תרגילExercise 5

מדף, צעד 8: כל ספר הוא מילוןShelf, step 8: each book is a dict

תזכורת: מה ביקשוReminder: the task

שדרגו את המדף: כל ספר נשמר כמילון עם title, author ו-genres (סט). הוסיפו שני ספרים מהקלט (כותרת, מחבר, ז'אנרים מופרדים בפסיק), והדפיסו את כל הז'אנרים הקיימים ממוינים, ואחריהם כמה ספרים יש.

Upgrade the shelf: each book is a dict with title, author and genres (a set). Add two books from input (title, author, comma-separated genres), then print all genres on the shelf sorted, then how many books there are.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
shelf.py
shelf = []
for _ in range(2):
    title = input()
    author = input()
    genres = {g.strip() for g in input().split(",")}
    shelf.append({"title": title, "author": author, "genres": genres})
all_genres = set()
for b in shelf:
    all_genres |= b["genres"]
print(sorted(all_genres))
print(len(shelf))
פלטOutput
Dune
Frank Herbert
sci-fi, classic
Matilda
Roald Dahl
kids, classic
['classic', 'kids', 'sci-fi']
2

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

אתגרChallenge 1

אנגרמותAnagrams

תזכורת: מה ביקשוReminder: the task

נתונה רשימת מילים. קבצו אנגרמות (מילים עם אותן אותיות) והדפיסו כל קבוצה עם יותר ממילה אחת, ממוינת, שורה לכל קבוצה, בסדר ההופעה.

Given a word list, group anagrams (same letters) and print each group with more than one word, sorted, one group per line, in order of appearance.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
words = ["listen", "google", "silent", "enlist", "banana", "elgoog"]
groups = {}
for w in words:
    key = "".join(sorted(w))
    groups.setdefault(key, []).append(w)
for g in groups.values():
    if len(g) > 1:
        print(sorted(g))
פלטOutput
['enlist', 'listen', 'silent']
['elgoog', 'google']

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

אתגרChallenge 2

היפוך מילוןInvert a dict

תזכורת: מה ביקשוReminder: the task

נתון book_genre = {"Dune": "sci-fi", "Emma": "classic", "Neuromancer": "sci-fi"}. בנו מילון הפוך: ז'אנר → רשימת ספרים (ממוינת), והדפיסו אותו.

Given book_genre = {"Dune": "sci-fi", "Emma": "classic", "Neuromancer": "sci-fi"}, build the inverse: genre → sorted list of books, and print it.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
book_genre = {"Dune": "sci-fi", "Emma": "classic", "Neuromancer": "sci-fi"}
by_genre = {}
for book, genre in book_genre.items():
    by_genre.setdefault(genre, []).append(book)
for genre in by_genre:
    by_genre[genre].sort()
print(by_genre)
פלטOutput
{'sci-fi': ['Dune', 'Neuromancer'], 'classic': ['Emma']}

יש יותר מדרך נכונה אחת. אם הפלט שלכם זהה, גם הפתרון שלכם נכון.There is more than one right way. If your output matches, your solution is right too.

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