Planning & pseudocode · תכנון וקוד פסאודו
Plan before you code
- An algorithm is a clear list of steps that solves a problem.
- Good programmers plan the steps before they type code.
- A plan helps you spot mistakes early and explain your idea.
תכנן לפני שתכתוב קוד
- אלגוריתם הוא רשימה ברורה של צעדים הפותרים בעיה.
- מתכנתים טובים מתכננים את השלבים לפני שהם כותבים קוד.
- תוכנית עוזרת לזהות טעויות מוקדם ולהסביר את הרעיון שלך.
Decomposition
- Decomposition means breaking a big problem into smaller parts.
- Solve each small part on its own.
- Small parts are easier to write, test, and fix.
פירוק
- פירוק פירונו לשבור בעיה גדולה לחלקים קטנים יותר.
- פתרונות כל חלק קטן באופן עצמאי.
- חלקים קטנים קלים יותר לכתיבה, לבדיקה ולתיקון.
Abstraction
- Abstraction means keeping only the details that matter.
- You hide the parts you do not need right now.
- A map is an abstraction: it shows roads, not every tree.
המרה
- המרה פירושה לשמור רק על הפרטים החשובים.
- אתה מסתיר את החלקים שאינך זקוק להם כרגע.
- מפה היא המרה: היא מראה דרכים, לא כל עץ.
Structured English
- Structured English writes the steps as plain numbered sentences.
- It is not real code, so anyone can read it.
אנגלית מבנית
- אנגלית מבנית כותבת את השלבים כמשפטים ממוספרים פשוטים.
- זהו קוד אמיתי לא, כך שכל אחד יכול לקרוא אותו.
1. Read the number.
2. If it can be divided by 2 with no remainder, it is even.
3. Otherwise it is odd.
4. Output the answer.
Flowcharts
- A flowchart draws the steps as boxes joined by arrows.
- A rectangle is a step; a diamond is a decision (yes / no).
תרשימי זרימה
- תרשים זרימה מצייר את השלבים בתוך מלבנות המחוברים על ידי חצים.
- מלבן הוא שלב; יהלום הוא החלטה (כן / לא).
( start )
|
[ read n ]
|
< n > 0 ? > --no--> [ output "not positive" ]
| yes
[ output "positive" ]
|
( end )
Three building blocks
- Sequence: steps run one after another.
- Selection:
if/elif/elsechooses a path. - Iteration:
for/whilerepeats steps.
שלושה בלוקים בונים
- רצף: שלבים רצים אחד אחרי השני.
- בחירה:
if/elif/elseבוחרים מסלול. - איטרציה:
for/whileחוזרים על השלבים.
In Cambridge pseudocode
- The same plan in pseudocode, then in Python below.
בפסאודוקוד קמברידג'
- אותה תוכנית בפסדוקוד, ולאחר מכן בפיתון למטה.
Total ← 0
FOR I ← 0 TO LENGTH(Numbers) - 1
Total ← Total + Numbers[I]
NEXT I
Average ← Total / LENGTH(Numbers)
OUTPUT Average
numbers = [4, 8, 6]
total = 0
for n in numbers:
total = total + n
average = total / len(numbers)
print(average)
Common mistakes
- Pseudocode is a plan in plain words — it does not have to run.
- Break the problem into small steps before you write any code.
- Plan the input → process → output.
טעויות נפוצות
- פסדוקוד הוא תוכנית במילים רגילות — היא אינה צריכה להתבצע.
- פצל את הבעיה לשלבים קטנים לפני שכתובים כל קוד.
- תכננו את הקלט → העיבוד → הפלט.
Now you try
- Each task gives you a plan in words. Turn it into Python.
- Press Check answer to test your code.
כעת תנסו בעצמכם
- לכל משימה יש תוכנית במילים. הפכו אותה לפיתון.
- לחץ על בדוק תשובה כדי לבדוק את הקוד שלך.
An algorithm is ordered steps · אלגוריתם הוא סדרת צעדים מסודרת
Pseudocode is just the steps in order, before you write real code. · קוד פסאודו הוא פשוט הצעדים בסדר, לפני שכותבים קוד אמיתי.
Follow this plan: read a whole number; if it divides by 2 with no remainder print Even, otherwise print Odd. For input 4, print Even. · עקוב תוכנית זו: קרא מספר שלם; אם הוא מתחלק ב-2 ללא שארית הדפ Even, אחרת הדפ Odd. עבור כניסה 4, הדפ Even.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Follow this plan: read a number N; add up every whole number from 1 to N; print the total. For input 5, print 15. · עקוב תוכנית זו: קרא מספר N; חשב את סכום כל המספרים השלמים מ-1 עד N; הדפ את הסך הכולל. עבור כניסה 5, הדפ 15.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Decompose this into a function. Write count_vowels(word) that returns how many letters of word are vowels (a e i o u, lowercase). · פצל זאת לפונקציה. כתוב count_vowels(word) שמחזיר את מספר האותיות בקבוצת word שהן元音 (a e i o u, אותיות קטנות).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Follow this plan for every number from 1 to 15: if it divides by both 3 and 5, print FizzBuzz; else if it divides by 3, print Fizz; else if it divides by 5, print Buzz; otherwise print the number. · עקוב תוכנית זו עבור כל מספר מ-1 עד 15: אם הוא מתחלק גם ב-3 וגם ב-5, הדפ FizzBuzz; אלא אם כן הוא מתחלק ב-3, הדפ Fizz; אלא אם כן הוא מתחלק ב-5, הדפ Buzz; אחרת הדפ את המספר עצמו.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.