📖 Chapter 1 of 12 · AI for New Learner- Senior 1 · Class 9
Chapter 1: Hello Python, Hello AI
In this chapter
- Why Python — the language of every Indian AI team.
- Aarush from Bhopal writes his first Python program.
- The four words you need: variable, function, list, print.
- Your first AI: a 4-line predictor you can actually run.
- Where to type and run your code — Replit, Colab, Thonny.
The Big Idea
Python is the language of every serious AI team in India — from ISRO to Sarvam AI to Niramai. It is also the friendliest language for a beginner. You can do real AI work in 4 lines. By the end of this chapter, you will have written and run your first AI program.
Did you know?
Python was invented in 1991 by Dutch programmer Guido van Rossum. It is named after the British comedy group ‘Monty Python’, NOT the snake! Today, India is the 2nd largest contributor of Python code in the world.
Builder Profile: Aarush
Bhopal, MP · Aarush, age 13
Aarush is from Bhopal. Three months ago, he could only USE apps. Today, he is writing one. He did not go to a coaching class. He installed a free tool called Thonny on his school laptop, watched two YouTube tutorials, and started typing.
His first program said ‘Hello AI!’ Two days later, he wrote a function to add two numbers. Last week he wrote a marks-average calculator for his sister’s class. “It is just typing,” he laughs. “But when you press enter and the computer DOES what you said — that feels like a superpower.”
Aarush is right. Coding is just clear instructions. The hard part is starting. You are about to start.
Your first Python — four words to know
Just four ideas are enough to start: a variable is a name for a value (age = 13); a function is a reusable bit of code (def greet(): ...); a list holds many values together (marks = [82, 75, 91]); and print shows a value on screen (print(age)).
💻 CODE LAB Your First AI — Predict School Bus Time
# Predict bus arrival from past observations
observations = [7.45, 7.50, 7.48, 7.52, 7.49]
def predict_average(times):
return sum(times) / len(times)
tomorrow = predict_average(observations)
print('Bus expected at', tomorrow)
# Output: Bus expected at 7.488
✍ WORKED EXAMPLE Cricket Score Predictor
Problem: Virat Kohli scored 45, 78, 22, 91, 64 in his last 5 ODI innings. Predict his next score using the mean, and say whether the mean is a good predictor for this player.
- Add all 5 scores: 45 + 78 + 22 + 91 + 64 = 300.
- Count the scores: there are 5 innings.
- Mean = total ÷ count = 300 ÷ 5 = 60. So predicted next score = 60.
- Check if the mean is sensible: scores range from 22 to 91 — a huge gap of 69 runs. Mean 60 is a fair guess but the player is INCONSISTENT.
- Lesson: for cricket scores the mean alone is weak. Real cricket AI uses recent form, opposition, pitch and weather. The mean is your STARTING POINT, not your final answer.
Show answer
✓ Answer: Predicted score = 60, but warn the user that the player’s spread is high.
Reading code — line by line
Every line says something. In predict_bus.py: observations = [7.45, 7.50, 7.48] is a LIST (square brackets, commas). def predict(times): starts a function whose input is ‘times’. return sum(times) / len(times) adds all values with sum(), counts them with len(), and divides to get the mean. ans = predict(observations) calls the function and saves the answer. print('Tomorrow:', ans) displays it with a label.
⚠ COMMON MISTAKE
✗ Mistake: Beginners often write print(observations) BEFORE defining ‘observations’. Python reads top-to-bottom — if you USE a variable before you CREATE it, you get ‘NameError: name X is not defined’.
✓ Fix: ALWAYS define a variable on a line ABOVE where you use it. If you see ‘NameError’, scroll up — the variable hasn’t been created yet, or you spelled it differently.
Solved illustrations
1. Why is Python so popular for AI?
Show answer
Answer: Three reasons: (1) Easy syntax — looks like English. (2) Huge free libraries — numpy, pandas, scikit-learn, PyTorch all written in Python. (3) Massive community — millions of solutions online when you get stuck. Every Indian AI startup hires Python coders.
2. Why is a function useful — can’t I just write the code each time?
Show answer
Answer: You CAN, but you would write the same code 100 times. A function is WRITE ONCE, USE MANY TIMES. The school-bus predictor can be reused for train predictions, exam-mark predictions, ANY average. Functions are the LEGO blocks of code.
3. What is the difference between a list and a variable?
Show answer
Answer: A variable holds ONE value: age = 13. A list holds MANY values together: ages = [13, 14, 12, 13]. Lists are how AI handles datasets — every row is a list, every column is a list, every image is a list of pixels.
4. Can I really write AI in 4 lines?
Show answer
Answer: Yes — but only the simplest kind. A 4-line predictor uses the mean. To predict cancer or translate Hindi, you need 100-200 lines using scikit-learn (Chapter 8). But the IDEA is the same: data in, prediction out.
5. Where do I run my code?
Show answer
Answer: FREE options: (1) Google Colab — runs in your browser, no install. (2) Replit — also browser-based. (3) Thonny — install on any laptop. ALL three are free and used by Indian schools. Pick one and stick with it.
Questions — Chapter 1
A. Fill in the blanks
- Python was invented in the year .
- The keyword to define a function is .
- A LIST in Python uses brackets around values.
- The function that counts how many items are in a list is ().
- Three free tools to run Python code: , , .
B. Predict the output
- nums = [10, 20, 30]; print(sum(nums)) →
- marks = [85, 90, 75]; print(len(marks)) →
- def double(x): return x*2; print(double(7)) →
C. Short answers
- Why is a function better than copy-pasting the same code 10 times?
- Write a 3-line Python program that finds the average of [82, 75, 91].
- Your friend’s code says ‘NameError’. What is one likely cause?
Ship-It Challenge
Open Replit or Colab today. Type the bus-time predictor. Run it. Screenshot. Send to a friend!
Check your understanding — Chapter 1
Tap an answer to check it instantly. These are for practice — nothing is saved or sent.
Q1. Why is Python so popular for AI?
- It is the only language that exists
- Easy English-like syntax, huge free libraries (numpy, pandas, sklearn), and a massive community
- It runs only on supercomputers
Show answer
B. Easy English-like syntax, huge free libraries (numpy, pandas, sklearn), and a massive community
Q2. What is the difference between a list and a variable?
- They are the same
- A variable holds ONE value; a list holds MANY values together
- A list can only hold text
Show answer
B. A variable holds ONE value; a list holds MANY values together
Q3. Your friend's code shows 'NameError'. What is one likely cause?
- The laptop is broken
- A variable was used before it was created, or its name was spelled differently
- Python is too slow
Show answer
B. A variable was used before it was created, or its name was spelled differently
Q4. Where can you run Python code for free?
- Only on a paid server
- Google Colab, Replit, or Thonny — all free and used by Indian schools
- Only inside a game
Show answer
B. Google Colab, Replit, or Thonny — all free and used by Indian schools