נקודות עצירה, צעד-אחר-צעד, צפייה במשתנים ושיטה למציאת באגים.
Breakpoints, stepping, watching variables and a method for finding bugs.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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
תקנו את הממוצעFix the average
הפונקציה מחזירה ממוצע שגוי. מצאו את הבאג (אפשר עם הדפסות) ותקנו. average([10, 20, 30]) צריך להיות 20.
The function returns a wrong average. Find the bug (prints help) and fix it. average([10, 20, 30]) should be 20.
איך הפלט אמור להיראות?What should the output look like?
20.0
main.py
רמזHint 1:הדפיסו את total ואת len(nums).Print total and len(nums).
רמזHint 2:החילוק צריך להיות במספר הפריטים, לא באחד פחות.Divide by the number of items, not one less.
הוסיפו ל-discount(price, percent) שני assert: המחיר חיובי, והאחוז בין 0 ל-100 (עם הודעות). הפונקציה מחזירה את המחיר אחרי הנחה, מעוגל ל-2.
Add two asserts to discount(price, percent): the price is positive, and percent is 0 to 100 (with messages). It returns the price after the discount, rounded to 2.
איך הפלט אמור להיראות?What should the output look like?
בגרסה הזו של המדף, מחיקת ספר מוחקת לפעמים ספר אחר, והספירה שגויה. מצאו ותקנו את שני הבאגים כך ש-remove_book תמחק לפי כותרת ו-count תחזיר את המספר הנכון.
In this shelf version, removing a book sometimes removes a different one, and the count is wrong. Find and fix both bugs so remove_book removes by title and count returns the right number.
איך הפלט אמור להיראות?What should the output look like?
['Dune', 'Matilda'] 2
shelf.py
רמזHint 1:הדפיסו את האינדקס ואת הספר שנמחק.Print the index and the book being removed.
רמזHint 2:enumerate מתחיל ב-0 כברירת מחדל.enumerate starts at 0 by default.
כתבו process(orders) שעוברת על מחירים: מחיר שלילי נרשם כ-WARNING ומדולג, מחיר 0 נרשם כ-INFO ומדולג, והשאר נסכמים. הגדירו logging לרמת INFO עם הפורמט %(levelname)s: %(message)s ל-stdout, והדפיסו את הסכום.
Write process(orders) over prices: a negative price logs a WARNING and is skipped, 0 logs INFO and is skipped, the rest are summed. Configure logging at INFO with format %(levelname)s: %(message)s to stdout, and print the total.
איך הפלט אמור להיראות?What should the output look like?