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.
المتغير هو صندوق مُسمّى
- المتغير هو اسم يخزن قيمة.
- تضع قيمة فيه باستخدام
=— وهذا يسمى الإسناد (assignment). - استخدم اسمًا واضحًا بحيث يكون البرنامج سهل القراءة.
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 (صح/خطأ) ←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.
الثوابت لا تتغير
- الثابت هو قيمة لا تتغير أثناء تشغيل البرنامج.
- Python ليس لديه كلمة مفتاحية خاصة، لذا نكتب الثوابت بـ
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. · اضغط تشغيل لرؤية المخرجات هنا.