נבנה על ידי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.

כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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. מה ידפיס הקוד?What does this print?
python
a = [1, 2]
b = a
b.append(3)
print(a)

2. מה מחזירה [3, 1, 2].sort()?What does [3, 1, 2].sort() return?

3. מה זה [x * x for x in range(4)]?What is [x * x for x in range(4)]?

תרגיליםExercises

תרגילExercise 1

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

נתונה הרשימה 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.

איך הפלט אמור להיראות?What should the output look like?
84.8
95 70
main.py
רמזHint 1: sum(scores) / len(scores)sum(scores) / len(scores)
רמזHint 2: max, minmax, min
לפתרוןSolution
תרגילExercise 2

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

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

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

איך הפלט אמור להיראות?What should the output look like?
milk
bread
eggs

3
bread
eggs
milk
main.py
רמזHint 1: רשימה ריקה + append בלולאה.Empty list + append in a loop.
רמזHint 2: if not item: breakif not item: break
לפתרוןSolution
תרגילExercise 3

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

נתונה 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.

איך הפלט אמור להיראות?What should the output look like?
['sci-fi', 'classic', 'kids']
main.py
רמזHint 1: רשימה ריקה unique.An empty list unique.
רמזHint 2: מוסיפים רק if t not in unique.Add only if t not in unique.
לפתרוןSolution
תרגילExercise 4

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

נתונות שתי רשימות מקבילות: 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).

איך הפלט אמור להיראות?What should the output look like?
Dune (412)
Emma (474)
Ulysses (730)
main.py
רמזHint 1: for t, p in zip(titles, pages):for t, p in zip(titles, pages):
רמזHint 2: if p > 400:if p > 400:
לפתרוןSolution
תרגילExercise 5

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

פרויקט מלווהCompanion project

שדרגו את התפריט: 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.

איך הפלט אמור להיראות?What should the output look like?
> 1
title: Dune
> 1
title: Emma
> 2
1. Dune
2. Emma
> 3
remove: Ulysses
not found
> 3
remove: Dune
> q
shelf.py
רמזHint 1: shelf = [] לפני הלולאה.shelf = [] before the loop.
רמזHint 2: enumerate(shelf, start=1) להדפסה.enumerate(shelf, start=1) for printing.
לפתרוןSolution

אתגרים לחזקיםChallenges for the brave

אתגרChallenge 1

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

קלטו מספר 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].

איך הפלט אמור להיראות?What should the output look like?
7
[4, 5, 1, 2, 3]
main.py
רמזHint 1: k = k % len(nums)k = k % len(nums)
רמזHint 2: nums[-k:] + nums[:-k]nums[-k:] + nums[:-k]
לפתרוןSolution
אתגרChallenge 2

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

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

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

איך הפלט אמור להיראות?What should the output look like?
a truly wonderful planet indeed
wonderful 9
main.py
רמזHint 1: words = s.split()words = s.split()
רמזHint 2: max(words, key=len) מחזירה את הראשונה בתיקו.max(words, key=len) returns the first on a tie.
לפתרוןSolution

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