Module 3: Prompt Engineering
Course: Programming with Free AI Tools — Build Real Websites and Apps | Audience: Ages 15–25, beginners | Module Goal: Write clear, effective prompts for code generation, debugging, and explanations. Learn bad vs good prompt examples.
Teaching Principle: A vague prompt gets a vague answer. Be specific, give context, and ask for verification steps.
Lesson 3.1 — Anatomy of a Good Prompt
Duration: 50 minutes
Learning Objectives
- List the 4 parts of a strong prompt: role, task, context, format.
- Rewrite a vague prompt into a clear one.
- Understand why context improves answers.
- Practice prompting for code with constraints.
Instructor Notes
Use the "bad vs good" contrast heavily. Show that adding language, experience level, and output format dramatically improves results. Encourage students to iterate.
Presentation Outline
- Why prompts matter (5 min).
- The 4-part prompt formula (15 min).
- Bad prompt vs good prompt examples (15 min).
- Live rewrite activity (10 min).
- Practice and feedback (5 min).
Demonstration
- Show bad prompt: "Make a website."
- Show AI's vague answer.
- Show good prompt: "Act as a web teacher. Write a single HTML page for a bakery with a title, one heading, and a paragraph. Output only the HTML code with comments."
- Show the clear, usable answer.
- Run the HTML to verify.
AI Prompts
- "Act as a coding teacher for beginners. Write a Python function to calculate the average of a list. Explain each line. Output code in a code block."
- "Rewrite this vague prompt into a clear one: 'code for login'."
Starter Code
Bad prompt:
"make a button"
Good prompt (fill in):
Role: ___________________
Task: ___________________
Context: ___________________
Format: ___________________
Final Code
Good prompt example:
Role: Act as a front-end teacher for beginners.
Task: Create an HTML button that shows an alert "Hello" when clicked.
Context: Plain HTML file, no frameworks, for a 16-year-old learner.
Format: Output only the HTML code with short comments.
Exercises
- Exercise 1: Rewrite 3 vague prompts from class into good ones.
- Exercise 2: Use your good prompt to generate code and verify it runs.
- Exercise 3: Swap prompts with a partner and rate clarity 1–5.
Homework
- Assignment 1: Write 5 reusable "good prompt" templates for coding tasks.
- Assignment 2: Generate a small HTML page using your best template and submit it.
Quiz
- Which is part of a strong prompt?
- a) Role
- b) Task
- c) Context
- d) All of the above ✅
- A vague prompt usually gives:
- a) Perfect code
- b) A vague or generic answer ✅
- c) Nothing
- d) An error message only
- Adding "for a beginner" to a prompt helps because:
- a) It makes the AI slower
- b) It sets the explanation level ✅
- c) It is required
- d) It changes the language
- Good prompts often specify:
- a) Output format ✅
- b) The weather
- c) Your birthday
- d) A random number
- The best way to improve an answer is to:
- a) Repeat the same vague prompt
- b) Add context and constraints, then iterate ✅
- c) Give up
- d) Shout
Lesson 3.2 — Prompting for Code Generation
Duration: 50 minutes
Learning Objectives
- Generate working code with precise prompts.
- Include language, framework, and constraints in prompts.
- Ask for comments and examples in generated code.
- Verify generated code by running it.
Instructor Notes
Teach students to specify the language and any libraries. Ask for small, runnable examples. Always end with "explain how to run this." Show a generated snippet running successfully.
Presentation Outline
- Recap prompt anatomy (5 min).
- Specifying language and framework (10 min).
- Asking for comments and run instructions (10 min).
- Live code generation demo (15 min).
- Verification routine (10 min).
Demonstration
- Prompt: "Act as a JS teacher. Write a function `isEven(n)` returning true if n is even. Include a comment and one example usage. Output only code."
- Copy into a file, run with Node or browser console.
- Show the output is correct.
- Modify the prompt to add edge cases and regenerate.
AI Prompts
- "Write a JavaScript function `capitalize(text)` that capitalizes the first letter. Include comments and a usage example. Output only code."
- "Generate a Python script that reads a name from input and prints a greeting. Add comments and run instructions."
Starter Code
// Starter: generate with AI, then verify
function isEven(n) {
// TODO: return true if n is even
}
Final Code
// Final
function isEven(n) {
return n % 2 === 0; // even numbers have no remainder when divided by 2
}
console.log(isEven(4)); // true
console.log(isEven(7)); // false
Exercises
- Exercise 1: Generate a function that counts vowels in a string; verify it.
- Exercise 2: Add run instructions to a prompt and confirm the code runs.
- Exercise 3: Generate code in two languages and compare clarity.
Homework
- Assignment 1: Generate and verify 3 small functions using precise prompts; submit code + proof it runs.
- Assignment 2: Write a prompt template for "generate a function with tests."
Quiz
- When generating code you should specify:
- a) The programming language ✅
- b) The color of your room
- c) Your favorite food
- d) None of these
- Asking for comments helps you:
- a) Waste tokens
- b) Understand the generated code ✅
- c) Break the code
- d) Hide errors
- After generating code you must:
- a) Submit immediately
- b) Run and verify it ✅
- c) Delete it
- d) Ignore output
- A precise prompt includes:
- a) Framework and constraints ✅
- b) Emojis only
- c) One word
- d) A joke
- "Output only code" is useful because:
- a) It confuses the AI
- b) It gives clean, copy-ready output ✅
- c) It is required
- d) It slows things down
Lesson 3.3 — Prompting for Debugging
Duration: 50 minutes
Learning Objectives
- Paste error messages effectively into a prompt.
- Ask AI to explain and fix bugs step by step.
- Distinguish a real fix from a guess.
- Verify the fix by re-running code.
Instructor Notes
Teach the "error + code + what you expected" formula. Show that AI may guess; students must test. Use a real broken snippet live.
Presentation Outline
- Why debugging with AI works (5 min).
- The debugging prompt formula (10 min).
- Bad vs good debugging prompts (10 min).
- Live debug demo (15 min).
- Verify-the-fix routine (10 min).
Demonstration
- Show broken code: `print("Hello"` (missing parenthesis).
- Bad prompt: "fix." Show weak answer.
- Good prompt: "This Python code errors: `print('Hello'`. Error: SyntaxError. What is wrong and how do I fix it? Show corrected code."
- Run the fix; confirm it works.
AI Prompts
- "My JavaScript code: `let x = 5; console.log(x` throws a SyntaxError. Explain the error and provide the corrected code."
- "This PHP gives a blank page: `<?php echo "Hi" ?`. Find the syntax error and fix it."
Starter Code
# Starter (broken): fix with AI help
def greet(name)
print("Hello " + name)
greet("Sam")
Final Code
# Final (fixed): added missing colon
def greet(name):
print("Hello " + name)
greet("Sam") # Output: Hello Sam
Exercises
- Exercise 1: Introduce a bug into working code, then use AI to find and fix it.
- Exercise 2: Write a debugging prompt that includes the error message.
- Exercise 3: Confirm the fix runs before marking the task done.
Homework
- Assignment 1: Collect 2 errors you hit this week and the AI fixes; submit both.
- Assignment 2: Write a reusable "debugging prompt" template.
Quiz
- A good debugging prompt includes:
- a) The error message ✅
- b) A joke
- c) Your address
- d) Nothing
- When AI gives a fix you should:
- a) Trust it blindly
- b) Test it by running the code ✅
- c) Delete the code
- d) Ignore it
- "What did you expect vs what happened" helps AI because:
- a) It wastes time
- b) It gives context to find the real bug ✅
- c) It is required
- d) It changes the language
- A SyntaxError usually means:
- a) The computer is broken
- b) The code violates language grammar rules ✅
- c) The AI is wrong
- d) Nothing
- AI debugging is best used as:
- a) A replacement for learning
- b) A helper that still needs your verification ✅
- c) A guarantee
- d) A game
Lesson 3.4 — Prompting for Explanations
Duration: 45 minutes
Learning Objectives
- Ask AI to explain code in simple terms.
- Request analogies for hard concepts.
- Summarize long code into bullet points.
- Build understanding, not just answers.
Instructor Notes
Explaining is where AI shines for learning. Teach "explain like I'm 15" and "give an analogy." Show how to turn a confusing snippet into a clear summary.
Presentation Outline
- Why explanations matter (5 min).
- "Explain like I'm 15" technique (10 min).
- Asking for analogies (10 min).
- Summarize-code demo (10 min).
- Build-your-own explanation (10 min).
Demonstration
- Paste a loop snippet into AI.
- Prompt: "Explain this Python loop like I'm 15, with an analogy."
- Show the analogy (e.g., checking each item on a shelf).
- Ask: "Summarize this function in 3 bullet points." Show result.
AI Prompts
- "Explain this JavaScript code like I'm 15, using a real-life analogy: `for (let i=0; i<3; i++){ console.log(i); }`"
- "Summarize what this Python function does in 3 bullet points and label its inputs and output."
Starter Code
// Starter: ask AI to explain this
for (let i = 0; i < 3; i++) {
console.log(i);
}
Final Code
AI explanation summary:
- The loop starts with i = 0.
- It runs while i is less than 3.
- Each run prints i, then adds 1 (i++).
Output: 0, 1, 2
Exercises
- Exercise 1: Paste a code snippet and ask for an analogy; write it down.
- Exercise 2: Summarize a function in 3 bullets using AI.
- Exercise 3: Teach the analogy back to a partner.
Homework
- Assignment 1: Pick one concept you find hard; get an AI analogy and write it in your own words.
- Assignment 2: Summarize a 10-line program into bullets and submit.
Quiz
- "Explain like I'm 15" is used to:
- a) Insult the AI
- b) Get a simple, clear explanation ✅
- c) Slow it down
- d) Change language
- An analogy helps because it:
- a) Confuses the topic
- b) Connects new ideas to familiar ones ✅
- c) Is required
- d) Breaks code
- Summarizing code into bullets helps you:
- a) Forget it
- b) Understand structure quickly ✅
- c) Delete it
- d) Hide bugs
- You should ask AI to explain code you don't understand:
- a) Never
- b) Yes, to build real understanding ✅
- c) Only if paid
- d) Only once
- The goal of explanation prompts is to:
- a) Copy answers
- b) Understand, not just receive code ✅
- c) Entertain
- d) Win arguments
الوحدة 3: هندسة الأوامر (Prompt Engineering)
الدورة: البرمجة بأدوات الذكاء الاصطناعي المجانية — بناء مواقع وتطبيقات حقيقية | الجمهور: أعمار 15–25، مبتدئون | هدف الوحدة: كتابة أوامر واضحة وفعّالة لتوليد الأكواد وتصحيحها وشرحها، والتعرّف على الفرق بين الأمر السيّئ والجيّد.
مبدأ التدريس: الأمر الغامض يعطي إجابة غامضة. كن محددًا، أعطِ سياقًا، واطلب خطوات للتحقق.
الدرس 3.1 — مكوّنات الأمر الجيّد
المدة: 50 دقيقة
أهداف التعلم
- سرد المكوّنات الأربعة للأمر القوي: الدور، المهمة، السياق، الصيغة.
- إعادة صياغة أمر غامض إلى أمر واضح.
- فهم سبب تحسّن الإجابات بوجود السياق.
- تدريب على طلب الأكواد مع قيود محددة.
ملاحظات للمدرّس
أبرز الفرق بين الأمر السيّئ والجيّد. بيّن أن إضافة اللغة ومستوى الخبرة وصيغة المخرجات يحسّن النتائج كثيرًا، وشجّع الطلاب على التكرار والتجربة.
خطة العرض
- لماذا الأوامر مهمة (5 دقائق).
- معادلة الأمر المكوّنة من 4 أجزاء (15 دقيقة).
- أمثلة أوامر سيّئة مقابل جيّدة (15 دقيقة).
- نشاط إعادة كتابة حي (10 دقائق).
- ممارسة وتغذية راجعة (5 دقائق).
ملخّص: الدرس يعلّم صيغة الأمر الجيّد (الدور/المهمة/السياق/الصيغة). قارن بين "اصنع موقعًا" وطلب محدّد يصف الصفحة والمخرجات. الكود والاختبارات موجودة بالنسخة الإنجليزية أدناه.
الدرس 3.2 — الأوامر لتوليد الأكواد
المدة: 50 دقيقة
أهداف التعلم
- توليد أكواد تعمل بأوامر دقيقة.
- تحديد اللغة والإطار والقيود في الأمر.
- طلب التعليقات والأمثلة في الكود المولّد.
- التحقق من الكود بتشغيله.
ملاحظات للمدرّس
علّم الطلاب تحديد اللغة والمكتبات، وطلب أمثلة صغيرة قابلة للتشغيل، ودائمًا أنهِ الأمر بـ "اشرح طريقة التشغيل". اعرض مقطعًا مولّدًا يعمل بنجاح.
خطة العرض
- تذكير بمكوّنات الأمر (5 دقائق).
- تحديد اللغة والإطار (10 دقائق).
- طلب التعليقات وتعليمات التشغيل (10 دقائق).
- عرض حي لتوليد الكود (15 دقيقة).
- روتين التحقق (10 دقائق).
ملخّص: استخدم أوامر مثل طلب دالة isEven مع تعليق ومثال، ثم شغّل الناتج. الكود النهائي في النسخة الإنجليزية.
الدرس 3.3 — الأوامر لتصحيح الأخطاء
المدة: 50 دقيقة
أهداف التعلم
- إدراج رسائل الخطأ في الأمر بفعالية.
- طلب تفسير وإصلاح الخطأ خطوة بخطوة.
- التمييز بين الإصلاح الحقيقي والتخمين.
- التحقق من الإصلاح بإعادة تشغيل الكود.
ملاحظات للمدرّس
علّم معادلة "الخطأ + الكود + ما كنت تتوقعه". بيّن أن الذكاء الاصطناعي قد يخمّن، فيجب على الطالب الاختبار. استخدم مقطعًا معطوبًا حقيقيًا أمامهم.
خطة العرض
- لماذا التصحيح بالذكاء الاصطناعي فعّال (5 دقائق).
- معادلة أمر التصحيح (10 دقائق).
- أوامر تصحيح سيّئة مقابل جيّدة (10 دقائق).
- عرض حي للتصحيح (15 دقيقة).
- روتين التأكد من الإصلاح (10 دقائق).
ملخّص: بدلاً من "صلّح"، أرفق الكود ورسالة الخطأ (مثل SyntaxError) وما تتوقعه. الكود المعطوب والمصلوح في النسخة الإنجليزية.
الدرس 3.4 — الأوامر لشرح الأكواد
المدة: 45 دقيقة
أهداف التعلم
- طلب شرح الكود بلغة بسيطة.
- طلب تشبيهات للمفاهيم الصعبة.
- تلخيص الأكواد الطويلة في نقاط.
- بناء الفهم لا مجرد الحصول على الإجابة.
ملاحظات للمدرّس
الشرح هو ما يبرع فيه الذكاء الاصطناعي للتعلّم. علّم "اشرح وكأن عمري 15" و"أعطِ تشبيهًا"، وبيّن كيف يتحول مقطع مشوّش إلى ملخّص واضح.
خطة العرض
- لماذا الشرح مهم (5 دقائق).
- تقنية "اشرح وكأن عمري 15" (10 دقائق).
- طلب التشبيهات (10 دقائق).
- عرض تلخيص الكود (10 دقائق).
- اصنع شرحك الخاص (10 دقائق).
ملخّص: اطلب شرح حلقة بـ "مثلًا على الرف"، واطلب تلخيص الدالة في 3 نقاط. الكود والملخّص في النسخة الإنجليزية.