חלקPart 1: יסודותFoundations
כ-3 שעות (כולל הפסקה)About 3 hours (with a break)
מה זה תכנות? התקנה וטרמינלWhat is programming? Setup & terminal
איך מחשב מבצע הוראות, התקנת Python ו-VS Code ב-Windows וב-Mac, הטרמינל, והתוכנית הראשונה עם print.
How a computer follows instructions, installing Python and VS Code on Windows and Mac, the terminal, and a first program with print.
הנקודות החשובותKey points
- תוכנית היא רשימת הוראות שמתבצעות לפי הסדר, מלמעלה למטה.A program is a list of instructions that run in order, top to bottom.
- המפרש של Python קורא את הקוד ומבצע אותו שורה אחרי שורה.Python's interpreter reads the code and runs it line by line.
- Windows: מסמנים Add to PATH ומריצים
python. Mac: מריציםpython3.Windows: tick Add to PATH and runpython. Mac: runpython3. - טרמינל:
pwd,ls/dir,cd,cd ..,mkdir.Terminal:pwd,ls/dir,cd,cd ..,mkdir. printמציגה ערכים. טקסט במירכאות, חישובים בלי. פסיק מפריד בין ערכים.printshows values. Text in quotes, calculations without. A comma separates values.- אופרטורים:
+ - * /וגם//(חילוק שלם),%(שארית),**(חזקה).Operators:+ - * /plus//(whole division),%(remainder),**(power). #מתחיל הערה. רווח בתחילת שורה הוא שגיאה (בינתיים).#starts a comment. A leading space is an error (for now).- קוראים שגיאה מלמטה: סוג → שורה → מה שונה ממה שהתכוונתי.Read an error from the bottom: type → line → what differs from what I meant.
מונחיםTerms
- תוכניתprogram: רשימה של הוראות שהמחשב מבצע לפי הסדר. ב-Python תוכנית היא בדרך כלל קובץ טקסט שנגמר ב-.py.A list of instructions the computer carries out in order. In Python a program is usually a text file ending in .py.
- תכנותprogramming: כתיבת הוראות מדויקות למחשב בשפה שהוא יודע לבצע, כדי שיפתור בעיה או יעשה משימה.Writing precise instructions for a computer, in a language it can run, so that it solves a problem or does a task.
- קודcode: הטקסט שאנחנו כותבים בשפת תכנות. "לכתוב קוד" זה לכתוב תוכנית.The text we write in a programming language. "Writing code" means writing a program.
- שפת תכנותprogramming language: שפה עם חוקים מדויקים (תחביר) שבה כותבים הוראות למחשב. Python היא שפת תכנות אחת מתוך הרבה.A language with exact rules (syntax) for writing instructions to a computer. Python is one programming language among many.
- PythonPython: שפת תכנות פופולרית שקל לקרוא ולכתוב. משמשת לאתרים, נתונים, AI, אוטומציה ומשחקים.A popular programming language that is easy to read and write. Used for websites, data, AI, automation and games.
- מפרש (interpreter)interpreter: התוכנה שקוראת את קוד ה-Python שלך ומבצעת אותו שורה אחרי שורה. כשמתקינים "Python", מתקינים בעצם את המפרש.The program that reads your Python code and runs it line by line. When you "install Python" you install the interpreter.
- טרמינלterminal: חלון שבו מקלידים פקודות טקסט למחשב במקום ללחוץ עם העכבר. ב-Mac נקרא Terminal, וב-Windows משתמשים ב-PowerShell.A window where you type text commands to the computer instead of clicking. On a Mac it is called Terminal; on Windows we use PowerShell.
- פקודהcommand: הוראה אחת שמקלידים בטרמינל ולוחצים Enter, למשל cd או python3 --version.One instruction typed in the terminal followed by Enter, for example cd or python3 --version.
- תיקייה (directory)folder (directory): מקום שמכיל קבצים ותיקיות אחרות. בטרמינל קוראים לה גם directory.A place that holds files and other folders. In the terminal it is also called a directory.
- נתיב (path)path: הכתובת של קובץ או תיקייה במחשב, למשל /Users/you/python-course/hello.py.The address of a file or folder on the computer, for example /Users/you/python-course/hello.py.
- תיקייה נוכחיתcurrent directory: התיקייה שהטרמינל "עומד" בה עכשיו. פקודות כמו python hello.py מחפשות קבצים בה.The folder the terminal is "standing in" right now. Commands like python hello.py look for files there.
- עורך קודcode editor: תוכנה לכתיבת קוד, עם צבעים, השלמה אוטומטית וכפתור הרצה. בקורס משתמשים ב-VS Code.An app for writing code, with colours, autocomplete and a run button. In this course we use VS Code.
- VS CodeVS Code: עורך קוד חינמי ופופולרי של Microsoft, שעובד ב-Windows, Mac ו-Linux.A free, popular code editor from Microsoft that runs on Windows, Mac and Linux.
- תוסף (extension)extension: חבילה שמוסיפה יכולות ל-VS Code. התוסף Python מוסיף הרצה, צבעים ובדיקת שגיאות.A package that adds features to VS Code. The Python extension adds running, colours and error checking.
- סקריפטscript: קובץ .py עם תוכנית שמריצים מההתחלה עד הסוף, למשל python3 hello.py.A .py file with a program you run from start to finish, for example python3 hello.py.
- printprint: פונקציה מובנית שמציגה טקסט או ערכים על המסך (בפלט).A built-in function that shows text or values on the screen (in the output).
- פונקציהfunction: פעולה עם שם שאפשר להפעיל ("לקרוא לה") עם סוגריים, כמו print(...). בחלק 2 נכתוב פונקציות משלנו.A named action you can run ("call") with parentheses, like print(...). In part 2 we write our own.
- מחרוזת (string)string: טקסט בתוך מירכאות, למשל "שלום" או 'Hi'. בשם הטיפוס: str.Text inside quotes, such as "hello" or 'Hi'. Its type name is str.
- פלטoutput: מה שהתוכנית מציגה החוצה, למשל טקסט שמודפס במסך.What the program shows to the outside world, for example text printed on the screen.
- אופרטורoperator: סימן שמבצע פעולה על ערכים: + - * / // % **.A symbol that does something with values: + - * / // % **.
- הערה (comment)comment: טקסט אחרי # ש-Python מתעלמת ממנו. כותבים הערות כדי להסביר את הקוד לבני אדם.Text after # that Python ignores. We write comments to explain code to humans.
- תחביר (syntax)syntax: חוקי הכתיבה של השפה: איפה שמים סוגריים, מירכאות, נקודתיים ורווחים.The writing rules of the language: where brackets, quotes, colons and spaces go.
- שגיאה (error)error: הודעה מ-Python שמשהו לא בסדר. השגיאה אומרת איפה (קובץ ושורה), מה הסוג, ומה ההסבר.A message from Python that something is wrong. It says where (file and line), what type, and an explanation.
- Tracebacktraceback: הדוח ש-Python מדפיסה כשתוכנית נופלת: המסלול שהוביל לשגיאה, ובשורה האחרונה סוג השגיאה וההסבר.The report Python prints when a program crashes: the path that led to the error, and on the last line the error type and message.
- באגbug: טעות בקוד שגורמת לתוכנית לעשות משהו אחר ממה שרצינו.A mistake in code that makes the program do something other than what we wanted.
- REPL (מצב אינטראקטיבי)REPL (interactive mode): מצב שבו Python מחכה לשורה אחת אחרי הסימן >>>, מבצעת אותה ומראה תוצאה מיד. נוח לניסויים קטנים.A mode where Python waits for one line after the >>> prompt, runs it and shows the result immediately. Handy for small experiments.
- הזחה (indentation)indentation: רווחים בתחילת שורה. ב-Python להזחה יש משמעות, ולכן רווח מיותר בהתחלה הוא שגיאה.Spaces at the start of a line. In Python indentation has meaning, so an extra leading space is an error.
- התקנהinstallation: הכנסת תוכנה למחשב כך שאפשר להפעיל אותה. בקורס מתקינים את Python ואת VS Code.Putting software on the computer so you can run it. In this course we install Python and VS Code.
- PATH (משתנה סביבה)PATH (environment variable): רשימת התיקיות שבהן הטרמינל מחפש פקודות. אם Python לא ב-PATH, הפקודה python "לא מוכרת".The list of folders where the terminal looks for commands. If Python is not on PATH, the python command is "not recognized".
- מספר שלם (int)integer (int): מספר בלי נקודה עשרונית, כמו 7 או -3. נלמד עליו לעומק במפגש 3.A number without a decimal point, like 7 or -3. We cover it in depth in session 3.
- מספר עשרוני (float)float: מספר עם נקודה עשרונית, כמו 3.5. חילוק עם / תמיד מחזיר float.A number with a decimal point, like 3.5. Division with / always gives a float.
Cheatsheet
הדפסהPrinting
print("שלום")
print("תוצאה:", 2 + 3)
print() # שורה ריקהprint("Hello")
print("Result:", 2 + 3)
print() # blank lineחשבוןArithmetic
7 + 3 # 10
7 / 2 # 3.5
7 // 2 # 3
7 % 2 # 1
2 ** 3 # 8הערותComments
# הערה בשורה שלמה
print(1) # הערה בסוף שורה# a full-line comment
print(1) # end-of-line commentטרמינל: MacTerminal: Mac
pwd
ls
cd python-course
cd ..
mkdir new-folder
python3 hello.pyטרמינל: WindowsTerminal: Windows
pwd
dir
cd python-course
cd ..
mkdir new-folder
python hello.pyREPLREPL
python3 # נכנסים
>>> 2 + 2
4
>>> exit() # יוצאיםpython3 # enter
>>> 2 + 2
4
>>> exit() # leaveשגיאות שפגשנוErrors we met
| שגיאהError | מה זה אומרWhat it means | מה עושיםWhat to do |
|---|---|---|
NameError | Python לא מכירה את השםPython doesn't know the name | בדקו איות ואותיות גדולות/קטנותCheck spelling and upper/lower case |
SyntaxError: unterminated string literal | מירכאות לא נסגרוQuotes not closed | הוסיפו מירכאות בסוף הטקסטAdd the closing quote |
SyntaxError: invalid syntax | השורה לא לפי חוקי השפהThe line breaks the language rules | חפשו משהו חסר או מיותר ליד ה-^Look for something missing or extra near the ^ |
IndentationError: unexpected indent | רווח מיותר בתחילת שורהAn extra space at the line start | מחקו את הרווחים בהתחלהDelete the leading spaces |
ZeroDivisionError | חילוק באפסDivision by zero | שנו את המחלקChange the divisor |
can't open file ... No such file | הקובץ לא בתיקייה הנוכחיתThe file isn't in the current folder | pwd, ls, ובדיקת שם הקובץpwd, ls, and check the file name |
'python' is not recognized | Python לא ב-PATH (Windows)Python isn't on PATH (Windows) | התקנה מחדש עם Add to PATH, או pyReinstall with Add to PATH, or use py |