📝 ملخص الصفحة
📚 مثال 2: المعاملات المنطقية
المفاهيم الأساسية
المعاملات المنطقية: عوامل تُستخدم في المقاطع البرمجية لفحص أكثر من شرط في جملة شرطية واحدة.
خريطة المفاهيم
```markmap
الوحدة الثالثة: البرمجة مع بايثون
أهداف التعلم
استخدام بيئة PyCharm Community
-
فتح بيئة باي تشارم
- اضغط على زر (بحث) Search
- اكتب PyCharm في شريط البحث، ثم اضغط عليه
- إنشاء مشروع جديد
- ينشئ البرنامج مجلدًا تلقائيًا باسم PythonProject
- يمكن تسمية المجلد باسم آخر من اختيارك
- ينشئ البرنامج ملف main.py تلقائيًا
- إنشاء ملف بايثون جديد
- اضغط على File (ملف)، وحدد New (جديد).
- حدد ملف Python File (ملف بايثون).
- اكتب اسما لملفك، واضغط على زر Enter.
- اكتب أمر بايثون بسيط.
- تشغيل المقطع البرمجي
- اضغط بزر الفأرة الأيمن على ملفك.
- اختر 'Run 'file name'' (تشغيل 'اسم الملف').
- تتم معالجة المقطع البرمجي وتظهر النتيجة أسفل الشاشة.
استخدام الجمل الشرطية
- استخدام أنواع مختلفة
- التمييز بينها
المعاملات الشرطية
- `>`: أكبر من
- `<`: أصغر من
- `==`: يساوي
- `>=`: أكبر من أو يساوي
- `<=`: أصغر من أو يساوي
- `!=`: لا يساوي
- الوظيفة: مقارنة القيم وإرجاع `True` أو `False`
- الاستخدام: داخل دوال مثل `if` و `while`
- الفرق بين `=` و `==`
- `=` (الإسناد): يغير قيمة المتغير.
- `==` (المساواة): يقرأ قيمة المتغير ويقارنها.
المعاملات المنطقية
- AND: تعود القيمة صواب (True) إذا كانت كلتا العبارتين صحيحة.
- OR: تعود القيمة صواب (True) إذا كانت إحدى العبارات صحيحة.
- NOT: تعود القيمة العكسية خطأ إذا كان الناتج صواب، وصواب إذا كان الناتج خطأ.
- جدول الحقيقة: يوضح الناتج لكل معامل منطقي (AND, OR, NOT) لجميع المدخلات الممكنة (True, False).
- ترتيب المعاملات في البرمجة: يحدد أولوية تنفيذ العمليات في التعبير.
- أمثلة تطبيقية
- `x=5, y=6, k=x<10 and y<8` ← الناتج: `True`
- `x=True, y=False, z=x==y` ← الناتج: `False`
- `x=True, y=False, m=(x or y) and (not False)` ← الناتج: `True`
- `x=5, y=6, n=x>y and (not y==6)` ← الناتج: `False`
استخدام الحلقات
- استخدام الحلقات في بايثون
- إيقاف الحلقة بعبارة الإيقاف
- استخدام الحلقات المتداخلة
- إنشاء أنماط باستخدام الحلقات
الدوال
- فهم ماهية الدالة
- بناء دوال جديدة
- التعامل مع معاملات الدالة
- تمييز المتغيرات المحلية والعامة
معالجة جداول البيانات
- استخدام التعليمات البرمجية لمعالجة جداول البيانات
الأدوات
- إصدار بيئة التواصل باي تشارم (PyCharm Community Edition)
- تُستخدم خصيصًا للغة بايثون
- متوافقة مع: ويندوز، لينكس، ماك أو إس
- يمكن تنزيلها مجانًا من: https://www.jetbrains.com/pycharm/
مراحل إنشاء البرنامج
- تحديد المشكلة
- كتابة الخطوات الخوارزمية
- رسم المخطط الانسيابي
- كتابة المقطع البرمجي
الأشكال المستخدمة في المخطط الانسيابي
- البيضاوي: البداية / النهاية
- متوازي الأضلاع: الإدخال / الإخراج
- المستطيل: العمليات
- المعين: اتخاذ قرار
- السهم (↓): عرض التسلسل
أمثلة على أنواع البيانات
الأعداد الصحيحة (int)
الأعداد الحقيقية (float)
- مثال: 3.0, -90.5, 0.0003, 4.5
النصوص والرموز (str)
- مثال: "
$", "hello", "Saad"
قيمة منطقية (bool)
إدخال البيانات من المستخدم
خطوات العملية
- طلب الإدخال: `print("الرجاء إدخال قيمة للمتغير x:")`
- استقبال القيمة: `x = input()`
- عرض النتيجة: `print("قيمة x:", x)`
العمليات الرياضية في بايثون
المقارنة مع الرياضيات
- الجمع: 2 + 4 ← `2 + 4`
- الطرح: 2 - 4 ← `2 - 4`
- الضرب: 2x4 ← `2 * 4`
- القسمة: 2 ÷ 4 ← `2 / 4`
- الأس: x² ← `x ** 2`
المعاملات (Operators) في بايثون
المعاملات الرياضية
- الرموز: `+ - / *`
- الوصف: تُستخدم لإجراء العمليات الحسابية
معاملات الإسناد
- الرموز: `= += -= *= /=`
- الوصف: تُستخدم لإسناد قيم للمتغيرات
المعاملات الشرطية
- الرموز: `> < == >= <= !=`
- الوصف: تُستخدم في مقارنة القيم أثناء كتابة الجمل الشرطية
المعاملات المنطقية
- الرموز: `and or not`
- الوصف: تُستخدم لفحص أكثر من شرط في جملة شرطية واحدة، وأيضًا لفحص نقيض الشرط
```
نقاط مهمة
- تقدم الصفحة أربعة أمثلة برمجية توضح كيفية عمل المعاملات المنطقية (`and`, `or`, `not`, `==`) مع القيم العددية والمنطقية.
- تحتوي كل أمثلة على مقطع برمجي ومربع إخراج يظهر النتيجة (`True` أو `False`).
- تختتم الصفحة بقسم "جرب بنفسك" يتضمن تمرينين تطبيقيين للطالب لحل المقطع البرمجي وتحديد الناتج.
📋 المحتوى المنظم
📖 محتوى تعليمي مفصّل
مثال 2: المعاملات المنطقية
نوع: محتوى تعليمي
مثال 2: المعاملات المنطقية
في الأمثلة التالية سترى كيفية استخدام العوامل المنطقية في المقاطع البرمجية.
مثال 2 - مقطع برمجي 1
نوع: محتوى تعليمي
x=5
y=6
k=x<10 and y<8
print(k)
مثال 2 - مقطع برمجي 2
نوع: محتوى تعليمي
x=True
y=False
z=x==y
print(z)
مثال 2 - مقطع برمجي 3
نوع: محتوى تعليمي
x=True
y=False
m=(x or y) and (not False)
print(m)
مثال 2 - مقطع برمجي 4
نوع: محتوى تعليمي
x=5
y=6
n=x>y and (not y==6)
print(n)
جرب بنفسك
نوع: QUESTION_ACTIVITY
جرب بنفسك
مقطع برمجي 1 (جرب بنفسك)
نوع: QUESTION_ACTIVITY
أوجد ناتج المقطع البرمجي التالي:
a=True
b=False
c=False
z=(a or b) and (not c)
print(z)
مقطع برمجي 2 (جرب بنفسك)
نوع: QUESTION_ACTIVITY
أوجد ناتج المقطع البرمجي التالي:
a=True
b=True
c=True
z=(a or b) and (not c)
print(z)
نوع: METADATA
وزارة التعليم
Ministry of Education
2025 - 1447
نوع: METADATA
118
🔍 عناصر مرئية
Code Snippet 1
A rectangular box containing Python-like code for logical operations. It initializes x=5, y=6, then calculates k as (x<10 AND y<8), and prints k.
Output for Code Snippet 1
A light blue rectangular box connected by an arrow from Code Block 1, displaying the output of the code.
Code Snippet 2
A rectangular box containing Python-like code. It initializes x=True, y=False, then calculates z as (x == y), and prints z.
Output for Code Snippet 2
A light blue rectangular box connected by an arrow from Code Block 2, displaying the output of the code.
Code Snippet 3
A rectangular box containing Python-like code. It initializes x=True, y=False, then calculates m as ((x or y) AND (not False)), and prints m.
Output for Code Snippet 3
A light blue rectangular box connected by an arrow from Code Block 3, displaying the output of the code.
Code Snippet 4
A rectangular box containing Python-like code. It initializes x=5, y=6, then calculates n as (x>y AND (not y==6)), and prints n.
Output for Code Snippet 4
A light blue rectangular box connected by an arrow from Code Block 4, displaying the output of the code.
جرب بنفسك
A stylized line drawing of a laptop with hands typing on the keyboard, accompanied by a speech bubble containing the text 'جرب بنفسك' (Try it yourself). This indicates an interactive exercise section.
Code Snippet for Activity 1
A rectangular box containing Python-like code for a 'Try It Yourself' activity. It initializes a=True, b=False, c=False, then calculates z as ((a or b) AND (not c)), and prints z. The output box is empty, requiring the user to determine the result.
Expected Output for Activity 1
An empty rectangular box connected by an arrow from Code Block 5, indicating where the user should write the output of the code. The expected output is 'True'.
Code Snippet for Activity 2
A rectangular box containing Python-like code for a 'Try It Yourself' activity. It initializes a=True, b=True, c=True, then calculates z as ((a or b) AND (not c)), and prints z. The output box is empty, requiring the user to determine the result.
Expected Output for Activity 2
An empty rectangular box connected by an arrow from Code Block 6, indicating where the user should write the output of the code. The expected output is 'False'.
📄 النص الكامل للصفحة
مثال 2: المعاملات المنطقية
في الأمثلة التالية سترى كيفية استخدام العوامل المنطقية في المقاطع البرمجية.
--- SECTION: مثال 2 - مقطع برمجي 1 ---
x=5
y=6
k=x<10 and y<8
print(k)
Output. What is the output of print(k)?
True
--- SECTION: مثال 2 - مقطع برمجي 2 ---
x=True
y=False
z=x==y
print(z)
Output. What is the output of print(z)?
False
--- SECTION: مثال 2 - مقطع برمجي 3 ---
x=True
y=False
m=(x or y) and (not False)
print(m)
Output. What is the output of print(m)?
True
--- SECTION: مثال 2 - مقطع برمجي 4 ---
x=5
y=6
n=x>y and (not y==6)
print(n)
Output. What is the output of print(n)?
False
--- SECTION: جرب بنفسك ---
جرب بنفسك
--- SECTION: مقطع برمجي 1 (جرب بنفسك) ---
أوجد ناتج المقطع البرمجي التالي:
a=True
b=False
c=False
z=(a or b) and (not c)
print(z)
Output. What is the output of print(z)? (Expected: True)
--- SECTION: مقطع برمجي 2 (جرب بنفسك) ---
أوجد ناتج المقطع البرمجي التالي:
a=True
b=True
c=True
z=(a or b) and (not c)
print(z)
Output. What is the output of print(z)? (Expected: False)
وزارة التعليم
Ministry of Education
2025 - 1447
118
--- VISUAL CONTEXT ---
**CODE_BLOCK**: Code Snippet 1
Description: A rectangular box containing Python-like code for logical operations. It initializes x=5, y=6, then calculates k as (x<10 AND y<8), and prints k.
Data: Code lines: x=5, y=6, k=x<10 and y<8, print(k)
Key Values: x=5, y=6, k=(5<10 and 6<8)
Context: Example demonstrating the 'and' logical operator.
**OUTPUT_BOX**: Output for Code Snippet 1
Description: A light blue rectangular box connected by an arrow from Code Block 1, displaying the output of the code.
Data: Output: True
Key Values: True
Context: The result of evaluating 'True and True'.
**CODE_BLOCK**: Code Snippet 2
Description: A rectangular box containing Python-like code. It initializes x=True, y=False, then calculates z as (x == y), and prints z.
Data: Code lines: x=True, y=False, z=x==y, print(z)
Key Values: x=True, y=False, z=(True==False)
Context: Example demonstrating the '==' equality operator with boolean values.
**OUTPUT_BOX**: Output for Code Snippet 2
Description: A light blue rectangular box connected by an arrow from Code Block 2, displaying the output of the code.
Data: Output: False
Key Values: False
Context: The result of evaluating 'True == False'.
**CODE_BLOCK**: Code Snippet 3
Description: A rectangular box containing Python-like code. It initializes x=True, y=False, then calculates m as ((x or y) AND (not False)), and prints m.
Data: Code lines: x=True, y=False, m=(x or y) and (not False), print(m)
Key Values: x=True, y=False, m=((True or False) and (not False))
Context: Example demonstrating combined 'or' and 'not' logical operators.
**OUTPUT_BOX**: Output for Code Snippet 3
Description: A light blue rectangular box connected by an arrow from Code Block 3, displaying the output of the code.
Data: Output: True
Key Values: True
Context: The result of evaluating '(True or False) and (not False)' which simplifies to 'True and True'.
**CODE_BLOCK**: Code Snippet 4
Description: A rectangular box containing Python-like code. It initializes x=5, y=6, then calculates n as (x>y AND (not y==6)), and prints n.
Data: Code lines: x=5, y=6, n=x>y and (not y==6), print(n)
Key Values: x=5, y=6, n=(5>6 and (not 6==6))
Context: Example demonstrating combined comparison and 'not' logical operators.
**OUTPUT_BOX**: Output for Code Snippet 4
Description: A light blue rectangular box connected by an arrow from Code Block 4, displaying the output of the code.
Data: Output: False
Key Values: False
Context: The result of evaluating '(5>6) and (not (6==6))' which simplifies to 'False and False'.
**FIGURE**: جرب بنفسك
Description: A stylized line drawing of a laptop with hands typing on the keyboard, accompanied by a speech bubble containing the text 'جرب بنفسك' (Try it yourself). This indicates an interactive exercise section.
Data: N/A
Context: Visual cue for a hands-on programming activity.
**CODE_BLOCK**: Code Snippet for Activity 1
Description: A rectangular box containing Python-like code for a 'Try It Yourself' activity. It initializes a=True, b=False, c=False, then calculates z as ((a or b) AND (not c)), and prints z. The output box is empty, requiring the user to determine the result.
Data: Code lines: a=True, b=False, c=False, z=(a or b) and (not c), print(z)
Key Values: a=True, b=False, c=False, z=((True or False) and (not False))
Context: An exercise for the user to apply knowledge of 'or' and 'not' logical operators.
**OUTPUT_BOX**: Expected Output for Activity 1
Description: An empty rectangular box connected by an arrow from Code Block 5, indicating where the user should write the output of the code. The expected output is 'True'.
Data: Expected Output: True
Key Values: ______
Context: Placeholder for the user's answer to the programming activity.
**CODE_BLOCK**: Code Snippet for Activity 2
Description: A rectangular box containing Python-like code for a 'Try It Yourself' activity. It initializes a=True, b=True, c=True, then calculates z as ((a or b) AND (not c)), and prints z. The output box is empty, requiring the user to determine the result.
Data: Code lines: a=True, b=True, c=True, z=(a or b) and (not c), print(z)
Key Values: a=True, b=True, c=True, z=((True or True) and (not True))
Context: An exercise for the user to apply knowledge of 'or' and 'not' logical operators with different boolean inputs.
**OUTPUT_BOX**: Expected Output for Activity 2
Description: An empty rectangular box connected by an arrow from Code Block 6, indicating where the user should write the output of the code. The expected output is 'False'.
Data: Expected Output: False
Key Values: ______
Context: Placeholder for the user's answer to the programming activity.
🎴 بطاقات تعليمية للمراجعة
عدد البطاقات: 5 بطاقة لهذه الصفحة
في لغة البرمجة، إذا كان x=5 و y=6، فما نتيجة التعبير المنطقي (x<10 and y<8)؟
- أ) False
- ب) True
- ج) Error
- د) None
الإجابة الصحيحة: b
الإجابة: True
الشرح: 1. قيّم الشرط الأول: x<10 → 5<10 → True.
2. قيّم الشرط الثاني: y<8 → 6<8 → True.
3. النتيجة: True and True → True.
تلميح: تذكر أن العامل المنطقي 'and' يعطي True فقط إذا كان كلا الشرطين صحيحين.
التصنيف: سؤال اختبار | المستوى: سهل
ما نتيجة تنفيذ الكود التالي في لغة برمجة تدعم العوامل المنطقية؟
x=True
y=False
z=x==y
print(z)
الإجابة الصحيحة: b
الإجابة: False
الشرح: 1. المتغير x يحتوي على القيمة المنطقية True.
2. المتغير y يحتوي على القيمة المنطقية False.
3. التعبير z = x == y يعني: هل True تساوي False؟
4. الإجابة هي False.
تلميح: العامل '==' يقارن بين قيمتين. هل القيمة المنطقية True تساوي القيمة المنطقية False؟
التصنيف: سؤال اختبار | المستوى: سهل
ما نتيجة التعبير المنطقي ((True or False) and (not False))؟
- أ) False
- ب) True
- ج) Error
- د) None
الإجابة الصحيحة: b
الإجابة: True
الشرح: 1. قيّم (True or False) → True.
2. قيّم (not False) → True.
3. النتيجة النهائية: True and True → True.
تلميح: ابدأ بتقييم ما داخل الأقواس. تذكر أولوية العمليات: الأقواس أولاً، ثم 'not'، ثم 'and' و 'or'.
التصنيف: مفهوم جوهري | المستوى: متوسط
إذا كان a=True, b=False, c=False، فما قيمة z بعد تنفيذ الكود التالي؟
z = (a or b) and (not c)
الإجابة الصحيحة: b
الإجابة: True
الشرح: 1. استبدل القيم: z = (True or False) and (not False).
2. قيّم (True or False) → True.
3. قيّم (not False) → True.
4. النتيجة: True and True → True.
تلميح: استبدل المتغيرات بقيمها المنطقية أولاً، ثم قم بالتقييم خطوة بخطوة.
التصنيف: مسألة تدريبية | المستوى: متوسط
ما هي الخاصية الأساسية للعامل المنطقي 'and'؟
- أ) يعطي نتيجة True إذا كان أحد المعاملين صحيحاً على الأقل.
- ب) يعكس القيمة المنطقية للمعامل.
- ج) يعطي نتيجة True فقط إذا كان كلا المعاملين (الشرطين) صحيحين.
- د) يقارن بين قيمتين ويعطي True إذا كانتا متساويتين.
الإجابة الصحيحة: c
الإجابة: يعطي نتيجة True فقط إذا كان كلا المعاملين (الشرطين) صحيحين.
الشرح: العامل المنطقي 'and' هو عامل اقتران. نتيجته تكون True فقط عندما تكون قيمة المعامل الأول والمعامل الثاني True معاً. في أي حالة أخرى (True and False, False and True, False and False) تكون النتيجة False.
تلميح: فكر في جدول الحقيقة للعامل 'and'.
التصنيف: تعريف | المستوى: سهل