Key-value pairs, immutable tuples, sets without duplicates.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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
תרגיליםExercises
תרגילExercise 1
מחירוןPrice list
נתון מילון מחירים. קלטו שם מוצר והדפיסו את המחיר שלו, או not found אם אין כזה.
Given a price dict, read a product name and print its price, or not found if missing.
איך הפלט אמור להיראות?What should the output look like?
מדף, צעד 8: כל ספר הוא מילוןShelf, step 8: each book is a dict
פרויקט מלווהCompanion project
שדרגו את המדף: כל ספר נשמר כמילון עם 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.
איך הפלט אמור להיראות?What should the output look like?
Dune
Frank Herbert
sci-fi, classic
Matilda
Roald Dahl
kids, classic
['classic', 'kids', 'sci-fi']
2
shelf.py
רמזHint 1:set(g.strip() for g in line.split(","))set(g.strip() for g in line.split(","))
רמזHint 2:איחוד של כל הסטים: all_genres |= b["genres"].Union all sets: all_genres |= b["genres"].