From "How Does AI Work?" to Writing Code 💻
Priya, 13, from Visakhapatnam — the same student from Lesson 1 — had spent the whole Class 8 year understanding how AI works. She understood neural networks, training data, language models, bias, and ethics.
But she had never written a line of code. "Is programming difficult?" she asked her teacher. "The first program is the hardest part," her teacher said. "After that, it gets easier every time."
In her first session with Google Colab — a free Python environment that runs in the browser — Priya wrote six lines of code that printed a personalised study plan. It was small. But it was hers. She had told the computer exactly what to do, and it did it.
🐍 Why Python?
Python is the most widely used programming language for AI, data science, and automation. Here is why it matters:
- Readable syntax: Python code looks almost like English.
print("Hello")does exactly what it says. - Free and open-source: Python itself is free. The AI libraries built on it (TensorFlow, PyTorch, scikit-learn, Hugging Face) are also free.
- Used by every major AI lab: Google, DeepMind, OpenAI, Anthropic, and Indian AI researchers all use Python as their primary programming language.
- Massive learning community: More tutorials, examples, and help resources than any other language.
🌐 Google Colab: Python in Your Browser
Google Colab is a free tool that lets you write and run Python in your browser — no installation, no setup, just a Google account.
1. Go to colab.research.google.com
2. Sign in with your Google account
3. Click "New Notebook"
4. You will see a cell where you can type Python code
5. Press Shift+Enter (or click the ▶ button) to run the code
Each "cell" in Colab is a small box where you type code. You run it, see the output, then type in the next cell. This is called a "notebook" — it is like an interactive textbook that runs code.
📝 Variables and Print
A variable is a named box that stores a value. You can put text, numbers, or lists into variables. The print() function displays a value on screen.
Your first Python code
# This is a comment — Python ignores lines starting with # # Comments are notes for humans reading the code name = "Priya" standard = 8 city = "Visakhapatnam" print("Hello, my name is", name) print("I am in Class", standard) print("I live in", city)
Hello, my name is Priya I am in Class 8 I live in Visakhapatnam
Change the values of name, standard, and city to your own information and run it again.
📋 Lists
A list stores multiple values in one variable. You write lists with square brackets, and separate items with commas.
subjects = ["Mathematics", "Science", "Social Studies", "English", "Telugu"] print("I am studying:", subjects) print("My first subject is:", subjects[0]) print("I have", len(subjects), "subjects")
I am studying: ['Mathematics', 'Science', 'Social Studies', 'English', 'Telugu'] My first subject is: Mathematics I have 5 subjects
subjects[0] = Mathematics, subjects[1] = Science.
🔀 If/Else — Making Decisions
An if/else statement lets your program make decisions. If a condition is true, do one thing; if not, do something else.
difficult_subject = "Mathematics" easy_subject = "English" if difficult_subject == "Mathematics": print("Mathematics needs 2 hours of practice today.") else: print("This subject needs 1 hour today.") if easy_subject == "Mathematics": print("Mathematics needs 2 hours of practice today.") else: print(easy_subject, "needs 1 hour today.")
Mathematics needs 2 hours of practice today. English needs 1 hour today.
🔁 For Loops — Doing Things Repeatedly
A for loop repeats a block of code for every item in a list. Instead of writing the same code five times for five subjects, you write it once and let the loop handle the repetition.
subjects = ["Mathematics", "Science", "Social Studies", "English", "Telugu"] for subject in subjects: print("Study", subject, "for 45 minutes")
Study Mathematics for 45 minutes Study Science for 45 minutes Study Social Studies for 45 minutes Study English for 45 minutes Study Telugu for 45 minutes
🚀 Your Working Program: The Study Plan Generator
Now put it all together. This program takes your list of subjects, determines how much time each needs (using if/else), and prints a complete study plan for the day.
# Study Plan Generator — Class 8 Python Project # Replace the subjects list and hard_subjects with your own! # Step 1: Your information student_name = "Priya" day = "Tuesday" # Step 2: Your subjects subjects = ["Mathematics", "Science", "Social Studies", "English", "Telugu"] # Step 3: Subjects that need extra time (change to YOUR difficult subjects) hard_subjects = ["Mathematics", "Science"] # Step 4: Print the header print("===============================") print("Study Plan for", student_name) print("Day:", day) print("===============================") print() # Step 5: Loop through subjects and assign time total_minutes = 0 for subject in subjects: if subject in hard_subjects: minutes = 60 note = "(needs extra practice)" else: minutes = 30 note = "" total_minutes = total_minutes + minutes print("📘", subject, ":", minutes, "minutes", note) # Step 6: Print the total print() print("===============================") print("Total study time:", total_minutes, "minutes") print("Remember to take a 10-minute break every 45 minutes!") print("===============================")
================================= Study Plan for Priya Day: Tuesday ================================= 📘 Mathematics : 60 minutes (needs extra practice) 📘 Science : 60 minutes (needs extra practice) 📘 Social Studies : 30 minutes 📘 English : 30 minutes 📘 Telugu : 30 minutes ================================= Total study time: 210 minutes Remember to take a 10-minute break every 45 minutes! =================================
- Change
student_nameto your name - Change
subjectsto your actual subject list - Change
hard_subjectsto the subjects you find most challenging - Can you add a section for "exam subjects" that get 90 minutes? Try it!
🐍 Quiz — Lesson 11
8 questions · Click your answer · Submit for your score
subjects = ["Maths", "Science", "English"], what does subjects[0] return?hard_subjects list?total_minutes = total_minutes + minutes do?💻 Hands-On Challenge — Extend the Program
Tip: in the print dialog, choose "Save as PDF" to download.Open Google Colab and complete at least one of these challenges:
- Personalise it: Replace the example subjects and hard_subjects with your actual Class 8 subjects. Run it and verify the output is correct.
- Add exam subjects: Create a third list called
exam_subjects. Modify the if/else to assign 90 minutes if the subject is in exam_subjects, 60 minutes if it is in hard_subjects, and 30 minutes otherwise. Tip: useeliffor the middle condition. - Add a break reminder: After every 2 subjects in the loop, print "Take a 10-minute break!" Hint: use a counter variable and check if it equals 2 or 4 using
if counter == 2.
📋 Note for Parents and Teachers
What this lesson covers: Why Python matters for AI, Google Colab setup (browser-based, no installation), variables, print(), strings and numbers, lists and indexing, if/else statements, for loops, and a complete working study plan generator program. This is a genuine first coding lesson with a real, runnable output.
Technical requirements: A device (phone, tablet, or computer) with a Google account and internet access is sufficient. Google Colab runs entirely in the browser — no Python installation, no special software. If students cannot access Colab, the code can also be typed at replit.com (also free and browser-based).