What We'll Learn Today
Welcome back, AI Superheroes! In Sessions 1 and 2, we learned what AI is and designed our Islamic chatbot "Noor." Today, we're going to learn how to actually build it using Pythonโa friendly programming language that talks to computers!
๐ฏ Learning Goals
- Understand Python โ What it is and why it's perfect for chatbots
- Learn basic coding โ Variables, input/output, if/else, and lists
- Build a real chatbot โ Create a working Islamic chatbot in Python
- Test and improve โ Run our chatbot and add more features
- Think like a coder โ Break problems into small steps
๐ The Story of Python the Friendly Snake ๐
Once upon a time, a man named Guido wanted to create a programming language that was easy to read and fun to useโlike having a friendly conversation with a computer!
He named it "Python" (after a funny TV show, not the snake!). Python became so loved that today, millions of people use it to build amazing things: chatbots, games, websites, and even AI!
Why do we love Python?
- โ It's easy to read (almost like English!)
- โ It's powerful (can build chatbots, games, AI)
- โ It's friendly (great for beginners)
- โ It's free (anyone can use it)
90-Minute Adventure Plan
Welcome & Story Time
Recap Sessions 1 & 2, introduce Python with the "Friendly Snake" story, show what we'll build today
Python Basics Part 1
Learn Variables & Print (storing information and showing messages)
Python Basics Part 2
Learn Input & If/Else (asking questions and making decisions)
Python Basics Part 3
Learn Lists (storing many Q&A pairs like flashcards)
Build Our Chatbot!
Put it all togetherโcode "Noor" the Islamic chatbot step by step
Test & Celebrate
Run our chatbots, share with the group, celebrate being coders!
What's Next?
How to extend the chatbot, practice at home, preview future sessions
Variables & Print: Storing & Showing Information
The Treasure Box Story
Imagine you have a treasure box with a label on it. You can put something inside (like your favorite toy's name) and later open the box to see what's inside!
In Python, we call these boxes "variables"โthey store information for us!
๐ Concept: Variables
A variable is like a labeled box that holds information.
# This is how we create a variable (treasure box)
chatbot_name = "Noor" # Put "Noor" in the box labeled "chatbot_name"
age = 10 # Put the number 10 in the box labeled "age"
is_kind = True # Put True (yes) in the box labeled "is_kind"
Teacher Tip
Use physical boxes or index cards to demonstrate variables! Write labels and put toy items inside to show how variables work.
๐ Concept: Print (Showing Messages)
To show a message on screen, we use print()โit's like asking the computer to speak!
# Tell the computer to say hello!
print("As-salamu alaykum!")
print("My name is", chatbot_name) # Show the treasure from our box!
Kids Activity #1: Create Your Own Variables
Task: Everyone creates 3 variables about themselves:
-
my_name= your name -
my_age= your age -
favorite_subject= what you love to learn
Then: Use print() to show these on screen!
Checkpoint #1
Amazing! You just learned how computers remember information! Give yourself a high-five! ๐
Input & If/Else: Asking Questions & Making Decisions
The Smart Robot Story
Imagine you meet a friendly robot. The robot asks: "What is your name?" You tell it, and the robot remembers!
Then the robot says: "If your name starts with 'A', I'll call you Amazing!"
This is exactly what input() and if/else do in Python!
๐ Concept: Input (Asking Questions)
input() lets your program ask the user a question and wait for an answer!
# Ask the user their name and store it in a variable
user_name = input("What is your name? ")
print("Nice to meet you,", user_name, "!")
๐ Concept: If/Else (Making Decisions)
Sometimes we want our program to do different things based on the answer. That's where if/else comes in!
# Ask a question
feeling = input("How are you feeling? (happy/sad) ")
# Make a decision based on the answer
if feeling == "happy":
print("Alhamdulillah! I'm happy too! ๐")
elif feeling == "sad":
print("Don't worry! Allah is always with you. ๐คฒ")
else:
print("I hope you have a blessed day!")
Teacher Tip
Act out if/else with kids! Say: "If you're wearing blue, stand up. Else, sit down." This shows decision-making in action!
Kids Activity #2: Build a Greeting Bot
Task: Create a simple program that:
- Asks: "What time is it? (morning/afternoon/evening)"
- If morning โ says "Good morning! Start your day with Bismillah!"
- If afternoon โ says "Good afternoon! Hope your day is blessed!"
- If evening โ says "Good evening! Don't forget your evening dua!"
๐ Checkpoint #2
Wow! Your programs can now talk AND think! You're becoming real coders! ๐ช
Lists: Storing Many Things at Once
๐ The Backpack Story
Imagine your school backpack. Instead of carrying one pencil, you carry a list of items: pencil, eraser, notebook, snack!
In Python, a list is like a backpackโit holds many items in one place!
๐ Concept: Lists
A list stores multiple items in order. We use square brackets [ ] to create them.
# Create a list of duas (prayers)
duas = ["Bismillah", "Alhamdulillah", "SubhanAllah"]
# Access items by their position (counting starts at 0!)
print(duas[0]) # Shows "Bismillah" (first item)
print(duas[1]) # Shows "Alhamdulillah" (second item)
# Add a new item to the list
duas.append("MashaAllah")
print(duas) # Shows all 4 duas!
Teacher Tip
Use flashcards arranged in a row to demonstrate lists! Number them 0, 1, 2, 3 to show how Python counts from zero.
๐ Why Lists Are Perfect for Chatbots
Our chatbot needs to remember MANY questions and answers! Lists help us organize them like flashcards.
# Store questions and answers together!
questions = ["Who created us?", "What do we say before eating?"]
answers = ["Allah created us", "We say Bismillah"]
# When someone asks question 0, give answer 0!
print("Q:", questions[0])
print("A:", answers[0])
Kids Activity #3: Create Your Q&A List
Task: Create two lists:
my_questions= 3 Islamic questions kids askmy_answers= 3 kind, simple answers
Example:
- Q: "How many times do we pray?" โ A: "We pray 5 times a day!"
๐ Checkpoint #3
You're ready! Now you know ALL the Python basics to build a chatbot! Let's do this! ๐
Building "Noor" - Our Islamic Chatbot
Time to put everything together! We'll build our chatbot step by step. Follow along and type the code with us!
Step 1: Welcome Message
First, let's make our chatbot introduce itself!
# Step 1: Welcome the user
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
print("โ As-salamu alaykum! ๐ โ")
print("โ I am Noor, your kind โ")
print("โ Islamic helper chatbot! โ")
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
print()
Teacher Tip
Ask a volunteer to read the welcome message out loud! Make it fun and engaging. Encourage kids to customize their chatbot's name.
Step 2: Get the User's Name
Let's ask who we're talking to!
# Step 2: Get user's name
user_name = input("What is your name? ")
print("Nice to meet you,", user_name, "! ๐")
print()
Step 3: Store Q&A Pairs
Now we create our knowledge baseโthe questions Noor knows about!
# Step 3: Create our Q&A database using lists
questions = [
"who created us",
"how many times do we pray",
"what do we say before eating",
"what is the quran",
"how should we treat others"
]
answers = [
"Allah (SWT) created us and everything in the universe! โ๏ธ",
"We pray 5 times a day: Fajr, Dhuhr, Asr, Maghrib, and Isha! ๐",
"We say 'Bismillah' (In the name of Allah) before eating! ๐",
"The Quran is Allah's beautiful message to guide us in life! ๐",
"We should treat everyone with kindness, respect, and love! โค๏ธ"
]
Volunteer Moment!
Ask 2-3 kids to suggest more questions and answers! Add them to the lists together as a group.
Step 4: The Chatbot Loop
This is the brain! Our chatbot will keep asking what the user wants to know.
# Step 4: Main chatbot conversation loop
print("You can ask me anything about Islam!")
print("Type 'bye' when you want to leave.\n")
while True:
# Get user's question
user_question = input(user_name + ": ").lower() # Convert to lowercase
# Check if user wants to exit
if user_question == "bye":
print("Noor: Wa alaykumu as-salam! May Allah bless you! ๐คฒ")
break # Exit the loop
# Search for the answer
found_answer = False
for i in range(len(questions)):
if questions[i] in user_question:
print("Noor:", answers[i])
found_answer = True
break
# If we don't know the answer
if not found_answer:
print("Noor: I'm still learning! Can you ask in a simpler way? ๐ค")
print() # Add spacing for readability
Teacher Tip
Explain the loop: "This is like a conversation that keeps going until we say 'bye'โjust like talking with a friend!" Walk through the logic slowly, one line at a time.
๐ฏ The Complete Chatbot Code
Here's everything put together! This is the full working chatbot:
# ================================================
# NOOR - My Kind Islamic Chatbot
# Created by: [Student's Name]
# Date: February 7, 2026
# ================================================
# Welcome message
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
print("โ As-salamu alaykum! ๐ โ")
print("โ I am Noor, your kind โ")
print("โ Islamic helper chatbot! โ")
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
print()
# Get user's name
user_name = input("What is your name? ")
print("Nice to meet you,", user_name, "! ๐\n")
# Knowledge base: Questions and Answers
questions = [
"who created us",
"how many times do we pray",
"what do we say before eating",
"what is the quran",
"how should we treat others",
"what is ramadan",
"who is prophet muhammad"
]
answers = [
"Allah (SWT) created us and everything in the universe! โ๏ธ",
"We pray 5 times a day: Fajr, Dhuhr, Asr, Maghrib, and Isha! ๐",
"We say 'Bismillah' (In the name of Allah) before eating! ๐",
"The Quran is Allah's beautiful message to guide us in life! ๐",
"We should treat everyone with kindness, respect, and love! โค๏ธ",
"Ramadan is the blessed month when we fast from dawn to sunset! ๐",
"Prophet Muhammad ๏ทบ is the last messenger of Allah and our role model! โจ"
]
# Main conversation loop
print("You can ask me anything about Islam!")
print("Type 'bye' when you want to leave.\n")
while True:
# Get user's question
user_question = input(user_name + ": ").lower()
# Check if user wants to exit
if user_question == "bye":
print("Noor: Wa alaykumu as-salam! May Allah bless you! ๐คฒ")
break
# Search for the answer in our knowledge base
found_answer = False
for i in range(len(questions)):
if questions[i] in user_question:
print("Noor:", answers[i])
found_answer = True
break
# If we don't know the answer
if not found_answer:
print("Noor: I'm still learning! Can you ask in a simpler way? ๐ค")
print()
print("Thank you for chatting with me, " + user_name + "! ๐")
๐ You Did It!
YOU JUST BUILT A REAL CHATBOT! Time to test it! ๐
Running & Testing Our Chatbot
How to Run Your Chatbot
- Save your code as
noor_chatbot.py - Open your terminal or command prompt
- Type:
python noor_chatbot.py - Press Enter and watch the magic! โจ
Test These Questions
Try Asking Noor:
- "Who created us?"
- "How many times do we pray?"
- "What is Ramadan?"
- "Tell me about Prophet Muhammad"
- "What happens when I ask something Noor doesn't know?"
Teacher Tip
Group Activity: Have kids pair up and test each other's chatbots! One asks questions while the other demonstrates. Celebrate when the chatbot responds correctly!
๐ What If Something Goes Wrong?
Don't worry! Every coder faces errors. Here's how to fix common ones:
Common Fixes
- IndentationError: Check your spacing! Python uses spaces to group code.
- NameError: Did you spell your variable name correctly?
- SyntaxError: Did you forget a quote mark (
") or colon (:)? - Chatbot doesn't respond: Make sure your question matches words in the questions list!
How to Make Your Chatbot Even Better
Now that you have a working chatbot, here are fun ways to extend it!
๐ก Extension Idea #1: Add More Q&A
# Just add more items to your lists!
questions.append("what are the five pillars")
answers.append("The five pillars are: Shahada, Salah, Zakat, Sawm, and Hajj! ๐")
๐ก Extension Idea #2: Add Greetings
# Respond to greetings!
if "assalam" in user_question or "salam" in user_question:
print("Noor: Wa alaykumu as-salam! How can I help you today? ๐")
๐ก Extension Idea #3: Add Stories
# Tell a beautiful Islamic story!
if "story" in user_question:
print("Noor: Let me tell you about Prophet Yunus (Jonah)...")
print("He was swallowed by a big fish, but never stopped praying!")
print("Allah saved him because he always had faith! ๐")
๐ก Extension Idea #4: Add Daily Duas
# Suggest a dua based on the situation
if "morning" in user_question:
print("Noor: Morning dua: Alhamdulillah for this new day! โ๏ธ")
elif "sleep" in user_question:
print("Noor: Before sleep, say: Bismika Allahumma ahya wa amut ๐")
๐ก Extension Idea #5: Emoji Mood
Make Noor show different moods based on the topic!
# Add emotions to responses
happy_emojis = ["๐", "๐", "๐", "โจ"]
peaceful_emojis = ["๐", "๐", "โฎ๏ธ", "๐คฒ"]
# Use them in responses!
print("Noor: MashaAllah!", happy_emojis[0])
Challenge for Home
Try adding 3 of these extensions to your chatbot this week! Bring it back to Session 4 to share!
Chatbot Best Practices - Being Responsible Coders
โ What Our Chatbot SHOULD Do
- โ Use kind, respectful language
- โ Give accurate Islamic information (verified by adults)
- โ Say "I don't know" instead of guessing
- โ Encourage learning and curiosity
- โ Respect all people regardless of background
โ What Our Chatbot Should NOT Do
- โ Share personal information (addresses, phone numbers)
- โ Give medical or legal advice
- โ Make fun of anyone or any belief
- โ Discuss adult topics
- โ Pretend to be a real scholar (we're learning!)
๐ก๏ธ The Safety Shield
Remember: Our chatbot is a learning tool, not a replacement for parents, teachers, or scholars!
If someone asks something inappropriate, our chatbot should say:
"I'm a learning chatbot for kids! Please ask a parent, teacher, or trusted adult about this question. ๐คฒ"
Adding a Safety Check
# List of topics we shouldn't discuss
unsafe_topics = ["password", "address", "phone", "credit card"]
# Check if question contains unsafe words
for unsafe_word in unsafe_topics:
if unsafe_word in user_question:
print("Noor: That's private information! Never share it online. ๐ก๏ธ")
continue # Skip to next question
What We Learned Today - AI Superhero Skills Unlocked!
๐ฏ Today's Big Wins
- ๐ Met Python - The friendly programming language
- ๐ฆ Variables - Treasure boxes that store information
- ๐จ๏ธ Print - Making the computer talk
- ๐ค Input - Asking questions and getting answers
- ๐ค If/Else - Making smart decisions
- ๐ Lists - Storing many things in a backpack
- ๐ค Built Noor - A real working Islamic chatbot!
- ๐ก๏ธ Safety First - Being responsible coders
๐ฃ๏ธ Tell Someone at Home
Homework Challenge
Teach your parent or sibling about:
- What a variable is (use the treasure box story!)
- How if/else works (use the robot story!)
- Show them your chatbot in action! ๐
๐ You Are Now:
- โ A Python programmer
- โ A chatbot builder
- โ A problem solver
- โ An AI Superhero who codes with Islamic values!
Future Adventures - Session 4 Preview
๐ Where We're Going Next
In our next session, we'll learn about:
- ๐ง Making Noor Smarter - Adding AI/ML concepts
- ๐จ Adding a Voice - Text-to-speech for our chatbot
- ๐ฏ Pattern Matching - Understanding questions better
- ๐พ Saving Data - Remembering past conversations
- ๐ Local LLMs - Introduction to on-premise AI models
๐ Practice at Home
Weekly Coding Challenge
Your Mission:
- Add 5 new Q&A pairs to your chatbot
- Teach Noor to tell one Islamic story
- Add a greeting and goodbye message
- Test your chatbot with 3 different people
- Write down what questions Noor struggled with
Bonus: Draw a flowchart showing how your chatbot thinks!
๐ Keep Learning Resources
- ๐ Python.org - Free tutorials for kids
- ๐ฎ Code.org - Fun coding games
- ๐บ Islamic Kids Programs - Learn Quran & Hadith facts to add to Noor
- ๐ฅ Our Online Community - Share your chatbot with other AI Superheroes!
๐ CONGRATULATIONS, CODE WARRIORS! ๐
You didn't just learn Python todayโyou built something real that can help others learn about Islam!
You are officially AI SUPERHERO CODERS! ๐ช๐ฆธโโ๏ธ๐ฆธโโ๏ธ
Keep coding, keep learning, keep being awesome! ๐
"Indeed, Allah loves those who are constantly striving to improve." - Inspired by Islamic teachings
๐ธ Share Your Journey!
Take a screenshot of your chatbot running and share it with your family! Don't forget to explain how it works using the stories we learned today! ๐