AI for Students · Class 8 · Age 12–13 · Lesson 11 of 12

Python Basics: Your First AI-Ready Code 🐍

You have understood how AI works for 10 lessons. Now write your first lines of Python — in the browser, no installation, and by the end you will have a working program that builds a personalised study plan.

📘 Class 8 · Lesson 11 🕐 60–75 min 💻 Hands-on coding 🆓 Free lesson
Illustrated scene: Indian student at a laptop with Python code on screen, a Colab notebook open, looking excited at their first output
Watch first · 2–3 minutes

Class 8 Lesson 11 — Python Basics

No sign-in needed · English narration · Safe for all school ages

Story · Priya Writes Her First Program

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.

👉 In this lesson, you will follow the same path as Priya — from zero to a working Python program that builds a study plan from a list of your subjects. No installation. Just a browser.
Section 1 of 7

🐍 Why Python?

Python is the most widely used programming language for AI, data science, and automation. Here is why it matters:

Section 2 of 7

🌐 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.

How to open Colab:
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.

Section 3 of 7

📝 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

Type this in Colab and press Shift+Enter:
# 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)
Output:
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.

Section 4 of 7

📋 Lists

A list stores multiple values in one variable. You write lists with square brackets, and separate items with commas.

Example:
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
Index counting: Python counts from 0. So the first item in the list is at index 0, the second is at index 1, and so on. subjects[0] = Mathematics, subjects[1] = Science.
Section 5 of 7

🔀 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.

Example — check if a subject needs extra time:
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.
Indentation matters in Python: The code inside an if block MUST be indented — use 4 spaces or one Tab. If you forget the indentation, Python will give an error. This is Python's way of showing which lines belong to which block.
Section 6 of 7

🔁 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.

Example — print a task for every subject:
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
Section 7 of 7

🚀 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.

Type this entire program in a single Colab cell and run it:
# 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("===============================")
Output:
=================================
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!
=================================
Now personalise it:
  • Change student_name to your name
  • Change subjects to your actual subject list
  • Change hard_subjects to the subjects you find most challenging
  • Can you add a section for "exam subjects" that get 90 minutes? Try it!
Variable ✅
List ✅
if/else ✅
for loop ✅
print() ✅
Working program ✅

🐍 Quiz — Lesson 11

8 questions · Click your answer · Submit for your score

1. Why is Python the most common language used for AI and machine learning?
2. In Python, what does a variable do?
3. In Python, if subjects = ["Maths", "Science", "English"], what does subjects[0] return?
4. What does a for loop do in Python?
5. In the study plan program, what is the purpose of the hard_subjects list?
6. Why is indentation (spacing) especially important in Python?
7. What does Google Colab allow you to do that makes it ideal for beginners?
8. In the study plan program, what does the line 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:

  1. Personalise it: Replace the example subjects and hard_subjects with your actual Class 8 subjects. Run it and verify the output is correct.
  2. 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: use elif for the middle condition.
  3. 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).

← Lesson 10: AI Projects Lesson 12: My Portfolio →