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

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

לולאותLoops

while, for, range, break ו-continue, ולולאת תפריט.

while, for, range, break and continue, and a menu loop.

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

לוח הכפל של מספרTimes table for a number

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

קלטו מספר והדפיסו את לוח הכפל שלו מ-1 עד 10, בפורמט 3 x 4 = 12.

Read a number and print its times table from 1 to 10, as 3 x 4 = 12.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
n = int(input())
for i in range(1, 11):
    print(f"{n} x {i} = {n * i}")
פלטOutput
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

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

תרגילExercise 2

סכום עד אפסSum until zero

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

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

Read numbers until 0 is typed, then print their sum.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
total = 0
while True:
    n = int(input())
    if n == 0:
        break
    total += n
print(total)
פלטOutput
10
20
30
0
60

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

תרגילExercise 3

ספירה לאחורCountdown

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

קלטו מספר והדפיסו ספירה לאחור עד 1 בשורה אחת עם רווחים, ואחריה 🚀.

Read a number and print a countdown to 1 on one line with spaces, then 🚀.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
n = int(input())
for i in range(n, 0, -1):
    print(i, end=" ")
print("🚀")
פלטOutput
5
5 4 3 2 1 🚀

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

תרגילExercise 4

ניחוש מספרGuess the number

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

המספר הסודי הוא 42. קלטו ניחושים עד שהמשתמש מצליח. אחרי כל ניחוש שגוי הדפיסו higher או lower, ובסוף got it in N tries.

The secret is 42. Read guesses until the user gets it. After each wrong guess print higher or lower, and finally got it in N tries.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
secret = 42
tries = 0
while True:
    guess = int(input())
    tries += 1
    if guess == secret:
        break
    elif guess < secret:
        print("higher")
    else:
        print("lower")
print(f"got it in {tries} tries")
פלטOutput
10
higher
50
lower
42
got it in 3 tries

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

תרגילExercise 5

מדף, צעד 6: תפריט ראשיShelf, step 6: the main menu

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

בנו תפריט שחוזר: 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: ?.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
shelf.py
count = 0
while True:
    choice = input("> ")
    if choice == "1":
        title = input("title: ")
        count += 1
        print(f"added: {title}")
    elif choice == "2":
        print(count)
    elif choice == "q":
        print("bye")
        break
    else:
        print("?")
פלטOutput
> 1
title: Dune
added: Dune
> 1
title: Emma
added: Emma
> 2
2
> x
?
> q
bye

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

אתגרChallenge 1

FizzBuzzFizzBuzz

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

הדפיסו את המספרים 1 עד 15, אבל במקום כפולות של 3 הדפיסו Fizz, במקום כפולות של 5 Buzz, ובמקום כפולות של שניהם FizzBuzz. (שאלת ראיון קלאסית!)

Print 1 to 15, but print Fizz instead of multiples of 3, Buzz for multiples of 5, and FizzBuzz for multiples of both. (A classic interview question!)

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
for i in range(1, 16):
    if i % 15 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)
פלטOutput
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

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

אתגרChallenge 2

משולש כוכביותStar triangle

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

קלטו גובה והדפיסו משולש ממורכז מכוכביות. לגובה 3 השורות הן: שני רווחים וכוכבית, רווח ושלוש כוכביות, חמש כוכביות.

Read a height and print a centred star triangle. For height 3 the rows are: two spaces and a star, a space and three stars, five stars.

סרטון מונפש: על מה לוחצים, מה כותבים ולמה, צעד אחר צעד.An animated movie: what to click, what to type and why, step by step.
איפהWhere
מהWhat
למהWhy
הפתרון המלא והפלט שלוFull solution and its output
main.py
h = int(input())
for i in range(1, h + 1):
    print(" " * (h - i) + "*" * (2 * i - 1))
פלטOutput
4
   *
  ***
 *****
*******

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

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