Variables, constants & data types · משתנים, קבועים וסוגי נתונים
A variable is a named box
- A variable is a name that stores a value.
- You put a value in with
=— this is called assignment. - Use a clear name so the program is easy to read.
משתנה היא קופסה עם שם
- משתנה הוא שם ששומר ערך.
- אתה מכניס ערך באמצעות
=— דבר זה נקרא הקצה. - השתמש בשם ברור כדי שהתוכנית תהיה קלה לקריאה.
age = 15
price = 2.50
name = "Ada"
print(age, price, name)
Variables as named boxes · משתנים כקופסאות ממונות שם
Each = puts a value into a named box you can use later. · כל = מכניס ערך לקופסה ממונה שם שתוכל להשתמש בה מאוחר יותר.
The five data types
- IGCSE uses five basic data types:
- integer (whole number) → Python
int; real (decimal) →float. - char (one letter), string (text) →
str; Boolean (True/False) →bool.
חמישה סוגי נתונים
- IGCSE משתמש בחמישה סוגי נתונים בסיסיים:
- integer (מספר שלם) → Python
int; real (מספר עשרוני) →float. - char (אות אחת), string (טקסט) →
str; Boolean (True/False) →bool.
score = 42 # integer
height = 1.75 # real
grade = "A" # char
town = "Cairo" # string
passed = True # Boolean
Constants stay the same
- A constant is a value that never changes while the program runs.
- Python has no special keyword, so we write constants in
CAPITALS. - This warns other readers: do not change me.
קבועים נשארים ללא שינוי
- קבוע הוא ערך שלא משתנה בזמן ביצוע התוכנית.
- לפייתון אין מילת מפתח ייעודית, ולכן אנו כותבים קבועים ב
CAPITALS. - זה מעורר אזהרה לקוראים האחרים: אל תשנו אותי.
PI = 3.14159
VAT_RATE = 0.20
print(PI)
Changing between types
input()gives a string, so convert it when you need a number.int(x)makes a whole number;float(x)a decimal;str(x)makes text.
מעבר בין סוגים
input()מחזיר טקסט, ולכן יש להמיר אותו כאשר נדרש מספר.int(x)יוצר מס שלם;float(x)מס עשרוני;str(x)יוצר טקסט.
n = int("5")
print(n + 1) # 6
print("Total: " + str(n)) # Total: 5
In the exam: DECLARE and CONSTANT
- Pseudocode names a type with
DECLARE, and fixes a value withCONSTANT.
במבחן: DECLARE וCONSTANT
- בפסאודוקוד מתאגד סוג עם
DECLARE, ומקובע ערך עםCONSTANT.
DECLARE Age : INTEGER
Age ← 15
CONSTANT Pi ← 3.14
Common mistakes
- Give a variable a value before you use it.
- A constant is a value you do not change — name it clearly.
- Keep the right type: numbers for maths, strings for text.
טעויות נפוצות
- תנו ערך למשתנה לפני שאתם משתמשים בו.
- קבוע הוא ערך שאינו משתנה — שמו בצורה ברורה.
- שמרו על הסוג הנכון: מספרים לחישובים, טקסט לטקסט.
Now you try
- Make variables and do a little maths with them.
- Press Check answer to test your code.
כעת תנסו בעצמכם
- צרו משתנים ובצעו איתם מעט חשבון.
- לחץ על בדוק תשובה כדי לבדוק את הקוד שלך.
The variables width and height are set for you. Work out the rectangle's area (width × height) and store it in a variable called area. · המשתנים width וheight נקבעו עבורך. חשב את השטח של המלבן (רוחב × גובה) ואחסן אותו במשתן הנקרא area.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
price is a real number and quantity is an integer. Work out the total cost (price × quantity). · price הוא מספר ממשי וquantity הוא שלם. חשב את העלות total (מחיר × כמות).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Read a whole number with input(), convert it with int(...), then print the number plus 3. For input 7, the output should be 10. · קרא מספר שלם עם input(), הפוך אותו עם int(...), והדפס את המספר עוד 3. עבור קלט 7, התוצאה צריכה להיות 10.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.