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

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

רשימותLists

יצירה, הוספה, מחיקה, מיון, ומה זה mutable.

Creating, adding, removing, sorting, and what mutable means.

נסו לפתור לבד לפני שמציצים. בנגן: חיצים במקלדת או הכפתורים. כל צעד מראה איפה (קובץ ושורה), מה כותבים ולמה.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

ממוצע ציוניםAverage score

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

נתונה הרשימה scores = [88, 92, 79, 95, 70]. הדפיסו את הממוצע מעוגל לספרה אחת, ואת הציון הגבוה והנמוך.

Given scores = [88, 92, 79, 95, 70], print the average rounded to one decimal, then the highest and lowest score.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
scores = [88, 92, 79, 95, 70]
print(round(sum(scores) / len(scores), 1))
print(max(scores), min(scores))
פלטOutput
84.8
95 70

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

תרגילExercise 2

רשימת קניותShopping list

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

קלטו פריטים עד שמקלידים שורה ריקה. בסוף הדפיסו כמה פריטים יש, ואת הרשימה ממוינת, פריט בשורה.

Read items until an empty line is typed. Then print how many items there are, and the list sorted, one per line.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
items = []
while True:
    item = input()
    if not item:
        break
    items.append(item)
print(len(items))
for it in sorted(items):
    print(it)
פלטOutput
milk
bread
eggs

3
bread
eggs
milk

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

תרגילExercise 3

ללא כפילויותNo duplicates

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

נתונה tags = ["sci-fi", "classic", "sci-fi", "kids", "classic"]. בנו רשימה חדשה בלי כפילויות, בסדר ההופעה הראשונה, והדפיסו אותה.

Given tags = ["sci-fi", "classic", "sci-fi", "kids", "classic"], build a new list without duplicates, in first-appearance order, 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
tags = ["sci-fi", "classic", "sci-fi", "kids", "classic"]
unique = []
for t in tags:
    if t not in unique:
        unique.append(t)
print(unique)
פלטOutput
['sci-fi', 'classic', 'kids']

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

תרגילExercise 4

ספרים ארוכיםLong books

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

נתונות שתי רשימות מקבילות: titles ו-pages. בעזרת zip הדפיסו רק ספרים עם יותר מ-400 עמודים, בפורמט Dune (412).

Given two parallel lists, titles and pages, use zip to print only books over 400 pages, as Dune (412).

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
titles = ["Dune", "Matilda", "Emma", "Ulysses"]
pages = [412, 240, 474, 730]
for t, p in zip(titles, pages):
    if p > 400:
        print(f"{t} ({p})")
פלטOutput
Dune (412)
Emma (474)
Ulysses (730)

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

תרגילExercise 5

מדף, צעד 7: רשימת ספרים אמיתיתShelf, step 7: a real list of books

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

שדרגו את התפריט: 1 מוסיף שם ספר לרשימה, 2 מדפיס את כל הספרים ממוספרים (1. Dune), 3 מוחק ספר לפי שם (אם הוא קיים, אחרת not found), q יוצא.

Upgrade the menu: 1 adds a title to a list, 2 prints all books numbered (1. Dune), 3 removes a book by title (if it exists, otherwise not found), q quits.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.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 = []
while True:
    choice = input("> ")
    if choice == "1":
        shelf.append(input("title: "))
    elif choice == "2":
        for i, t in enumerate(shelf, start=1):
            print(f"{i}. {t}")
    elif choice == "3":
        t = input("remove: ")
        if t in shelf:
            shelf.remove(t)
        else:
            print("not found")
    elif choice == "q":
        break
פלטOutput
> 1
title: Dune
> 1
title: Emma
> 2
1. Dune
2. Emma
> 3
remove: Ulysses
not found
> 3
remove: Dune
> q

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

אתגרChallenge 1

סיבוב רשימהRotate a list

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

קלטו מספר k. סובבו את nums = [1, 2, 3, 4, 5] ימינה k מקומות (k יכול להיות גדול מאורך הרשימה) והדפיסו. ל-k=2: [4, 5, 1, 2, 3].

Read k. Rotate nums = [1, 2, 3, 4, 5] right by k places (k may exceed the length) and print it. For k=2: [4, 5, 1, 2, 3].

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
nums = [1, 2, 3, 4, 5]
k = int(input()) % len(nums)
print(nums[-k:] + nums[:-k] if k else nums)
פלטOutput
7
[4, 5, 1, 2, 3]

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

אתגרChallenge 2

המילה הארוכה ביותרLongest word

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

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

Read a sentence. Print its longest word (the first if several tie) and its length.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.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 = input().split()
longest = max(words, key=len)
print(longest, len(longest))
פלטOutput
a truly wonderful planet indeed
wonderful 9

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

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