Planning & pseudocode · التخطيط والكود الوهمي
Plan before you code
- An algorithm is a clear list of steps that solves a problem.
- Good programmers plan the steps before they type code.
- A plan helps you spot mistakes early and explain your idea.
خطط قبل أن تكتب الكود
- الخوارزمية هي قائمة واضحة من الخطوات تحل مشكلة ما.
- المبرمجون الجيدون يخططون للخطوات قبل كتابة الكود.
- الخطط يساعدك على اكتشاف الأخطاء مبكرًا وشرح فكرتك.
Decomposition
- Decomposition means breaking a big problem into smaller parts.
- Solve each small part on its own.
- Small parts are easier to write, test, and fix.
التحليل التفصيلي (Decomposition)
- التحليل التفصيلي يعني تقسيم مشكلة كبيرة إلى أجزاء أصغر.
- حل كل جزء صغير على حدة.
- الأجزاء الصغيرة أسهل في الكتابة والاختبار والإصلاح.
Abstraction
- Abstraction means keeping only the details that matter.
- You hide the parts you do not need right now.
- A map is an abstraction: it shows roads, not every tree.
التجريد (Abstraction)
- التجريد يعني الاحتفاظ فقط بالتفاصيل المهمة.
- تخفي الأجزاء التي لا تحتاجها الآن.
- الخريطة تجريد: تظهر الطرق، لا كل شجرة.
Structured English
- Structured English writes the steps as plain numbered sentences.
- It is not real code, so anyone can read it.
الإنجليزية المنظمة (Structured English)
- الإنجليزية المنظمة تكتب الخطوات كجمل مرقمة عادية.
- ليست كودًا فعليًا، لذا يمكن لأي شخص قراءتها.
1. Read the number.
2. If it can be divided by 2 with no remainder, it is even.
3. Otherwise it is odd.
4. Output the answer.
Flowcharts
- A flowchart draws the steps as boxes joined by arrows.
- A rectangle is a step; a diamond is a decision (yes / no).
المخططات الانسيابية (Flowcharts)
- المخطط الانسيابي يرسم الخطوات كمربعات متصلة بأسهم.
- المستطيل يمثل خطوة؛ المعين يمثل قرارًا (نعم / لا).
( start )
|
[ read n ]
|
< n > 0 ? > --no--> [ output "not positive" ]
| yes
[ output "positive" ]
|
( end )
Three building blocks
- Sequence: steps run one after another.
- Selection:
if/elif/elsechooses a path. - Iteration:
for/whilerepeats steps.
ثلاث ركائز
- التسلسل: الخطوات تنفذ واحدة تلو الأخرى.
- الاختيار:
if/elif/elseتختار مساراً. - التكرار:
for/whileيعيد تنفيذ الخطوات.
In Cambridge pseudocode
- The same plan in pseudocode, then in Python below.
في الرمز الوهمي لكامبريدج
- نفس الخطة بلغة الوصف الوهمي، ثم في بايثون أدناه.
Total ← 0
FOR I ← 0 TO LENGTH(Numbers) - 1
Total ← Total + Numbers[I]
NEXT I
Average ← Total / LENGTH(Numbers)
OUTPUT Average
numbers = [4, 8, 6]
total = 0
for n in numbers:
total = total + n
average = total / len(numbers)
print(average)
Common mistakes
- Pseudocode is a plan in plain words — it does not have to run.
- Break the problem into small steps before you write any code.
- Plan the input → process → output.
أخطاء شائعة
- الوصف الوهمي هو خطة بكلمات عادية — لا يشترط أن يعمل برمجياً.
- قسّم المشكلة إلى خطوات صغيرة قبل كتابة أي كود.
- خطّط للمدخلات → المعالجة → المخرجات.
Now you try
- Each task gives you a plan in words. Turn it into Python.
- Press Check answer to test your code.
الآن جرب بنفسك
- كل مهمة تعطيك خطة بالكلمات. حوّلها إلى بايثون.
- اضغط على تحقق من الإجابة لاختبار الكود الخاص بك.
An algorithm is ordered steps · الخوارزمية هي خطوات مرتبة
Pseudocode is just the steps in order, before you write real code. · الكود الوهمي هو فقط الخطوات بالترتيب، قبل كتابة الكود الفعلي.
Follow this plan: read a whole number; if it divides by 2 with no remainder print Even, otherwise print Odd. For input 4, print Even. · اتبع هذه الخطة: اقرأ عدداً صحيحاً؛ إذا كان يقبل القسمة على 2 بدون باقٍ اطبع Even، وإلا اطبع Odd. بالنسبة للمدخل 4، اطبع Even.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Follow this plan: read a number N; add up every whole number from 1 to N; print the total. For input 5, print 15. · اتبع هذا الخطة: اقرأ عددًا N؛ اجمع كل عدد صحيح من 1 إلى N؛ اطبع المجموع. للمدخل 5، اطبع 15.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Decompose this into a function. Write count_vowels(word) that returns how many letters of word are vowels (a e i o u, lowercase). · فكّك هذا إلى دالة. اكتب count_vowels(word) تُرجع عدد حروف word التي هي حروف متحركة (a e i o u، أحرف صغيرة).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Follow this plan for every number from 1 to 15: if it divides by both 3 and 5, print FizzBuzz; else if it divides by 3, print Fizz; else if it divides by 5, print Buzz; otherwise print the number. · اتبع هذه الخطة لكل عدد من 1 إلى 15: إذا قُسِم على كل من 3 و 5، اطبع FizzBuzz؛ وإلا إذا قُسِم على 3، اطبع Fizz؛ وإلا إذا قُسِم على 5، اطبع Buzz؛ وإلا اطبع العدد.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.