while, for, range, break ו-continue, ולולאת תפריט.
while, for, range, break and continue, and a menu loop.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-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
לוח הכפל של מספרTimes table for a number
קלטו מספר והדפיסו את לוח הכפל שלו מ-1 עד 10, בפורמט 3 x 4 = 12.
Read a number and print its times table from 1 to 10, as 3 x 4 = 12.
איך הפלט אמור להיראות?What should the output look like?
7
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
main.py
רמזHint 1:for i in range(1, 11):for i in range(1, 11):
רמזHint 2:print(f"{n} x {i} = {n * i}")print(f"{n} x {i} = {n * i}")
מדף, צעד 6: תפריט ראשיShelf, step 6: the main menu
פרויקט מלווהCompanion project
בנו תפריט שחוזר: 1 מוסיף ספר (קולט שם ומדפיס added: <שם>), 2 מדפיס כמה ספרים נוספו, q יוצא ומדפיס bye. כל בחירה אחרת: ?.
Build a repeating menu: 1 adds a book (reads a title and prints added: <title>), 2 prints how many were added, q quits and prints bye. Anything else: ?.
איך הפלט אמור להיראות?What should the output look like?
> 1
title: Dune
added: Dune
> 1
title: Emma
added: Emma
> 2
2
> x
?
> q
bye
shelf.py
רמזHint 1:מונה count = 0 לפני הלולאה.A counter count = 0 before the loop.