Numbers & operators · الأعداد & العمليات
Two kinds of number
- An integer (
int) is a whole number, like7or-3. - A float is a number with a decimal point, like
2.5. - Division with
/always gives a float, even4 / 2→2.0.
نوعان من الأرقام
- العدد الصحيح (
int) هو عدد صحيح، مثل7أو-3. - العشر العائم هو عدد به فاصلة عشرية، مثل
2.5. - القسمة باستخدام
/تُعطي دائمًا عددًا عائمًا، حتى4 / 2→2.0.
Add, subtract, multiply, divide
+adds,-subtracts,*multiplies,/divides.- You can use them with variables or with plain numbers.
- Spaces around operators are optional but make code easier to read.
الجمع، الطرح، الضرب، القسمة
+يجمع،-يطرح،*يضرب،/يقسم.- يمكنك استخدامها مع المتغيرات أو مع الأرقام العادية.
- المسافات حول المعاملات اختيارية لكنها تجعل الكود أسهل في القراءة.
print(7 + 2)
print(7 - 2)
print(7 * 2)
print(7 / 2)
Whole-number division, remainder, powers
//divides and keeps only the whole part (floor division).%gives the remainder (called modulo).**raises to a power:2 ** 3is 2×2×2.
قسمة الأعداد الصحيحة، الباقي، الأسس
//تقسم وتحتفظ فقط بالجزء الصحيح (قسمة الأرضية).%يعطي الباقي (يُسمى باقي القسمة).**يرفع للأس:2 ** 3هي 2×2×2.
print(7 // 2)
print(7 % 2)
print(2 ** 5)
Order of operations
- Python does
**first, then*///%, then+-. - This is the same order you use in maths.
- Use parentheses
(...)to change the order.
ترتيب العمليات
- بايثون ينفذ
**أولاً، ثم*///%، ثم+-. - هذا هو نفس الترتيب الذي تستخدمه في الرياضيات.
- استخدم الأقواس
(...)لتغيير الترتيب.
print(2 + 3 * 4)
print((2 + 3) * 4)
Common mistakes
/always gives a float (4 / 2is2.0); use//when you want a whole number.- Power is
**, not^. "3" + "4"joins text into"34"— it does not add to7.
أخطاء شائعة
/تُعطي دائمًا عددًا عائمًا (4 / 2هي2.0)؛ استخدم//عندما تريد عددًا صحيحًا.- الأس هو
**، وليس^. "3" + "4"يدمج النصوص في"34"— فهو لا يجمع7.
Now you try
- Store each answer in the variable named in the task.
- Press Check answer to test your code.
الآن جرب بنفسك
- احفظ كل إجابة في المتغير المسمى في المهمة.
- اضغط على تحقق من الإجابة لاختبار الكود الخاص بك.
Order of operations · ترتيب العمليات
Python evaluates × and ÷ before + and −, left to right. · يقيّم بايثون الضرب × والقسمة ÷ قبل الجمع + والطرح −، من اليسار إلى اليمين.
Set length to 8 and width to 5. Then store their product in a variable called area. · ضع length عند 8 وwidth عند 5. ثم خزن حاصل ضربهما في متغير اسمه area.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
You share 17 sweets among 5 children. Store how many each child gets in each (use //), and how many are left over in left (use %). · توزع 17 حلويات على 5 أطفال. خزن عدد الحلويات التي يحصل عليها كل طفل في each (استخدم //)، وعدد الحلويات المتبقية في left (استخدم %).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Store 3 ** 2 + 1 in result. Then use parentheses to store (3 + 1) ** 2 in grouped. · خزن 3 ** 2 + 1 في result. ثم استخدم الأقواس لخزن (3 + 1) ** 2 في grouped.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
celsius is 37. Store the temperature in Fahrenheit in fahrenheit, using the formula celsius × 9 ÷ 5 + 32. · celsius هي 37. خزن درجة الحرارة بالفهرنهايت في fahrenheit، باستخدام الصيغة celsius × 9 ÷ 5 + 32.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.