Class 10 AI Unit 7: Advance Python – Notes (Jupyter, Python Basics, Libraries) | CBSE Code 417

Class 10 · AI (417) · Part B · Unit 7
Advance Python

Jupyter Notebook, virtual environments, Python basics, built-in functions and the libraries you'll use in your practical file.

Practical-only unit10 hrsPractical File + Exam
๐Ÿ“Œ How this unit is tested

Unit 7 has no theory marks, but it's the backbone of your practical file (15 programs) and practical exam. Weak Python = a tough practical exam. So practise every snippet on this page yourself.

In this chapter
  1. Jupyter Notebook and Anaconda
  2. Virtual environments and installing packages
  3. Python fundamentals: variables, data types, operators
  4. Decisions and loops
  5. Lists and built-in functions
  6. Libraries for AI: NumPy, Pandas, Matplotlib, OpenCV
๐Ÿ“– Why Python?

If AI is a car, Python is the steering wheel. Almost every AI tool (TensorFlow, OpenCV, ChatGPT's training code) talks Python. The good news: Python reads almost like English. if marks > 33: print("Pass") — you can probably guess what that does already!

1. Jupyter Notebook

Jupyter Notebook is a web-based tool where you write and run Python code in small blocks called cells, and see the output right below each cell. You can also add notes, headings and charts. It's perfect for AI and data science because you can test step by step.

  • Code cell: contains Python code. Press Shift + Enter to run it.
  • Markdown cell: contains text, headings and notes.
  • Files are saved with the extension .ipynb (IPython Notebook).
๐Ÿ““ Jupyter · my_first_notebook.ipynb In [1]: print("Hello AI") Hello AI My AI Practical← Markdown cell In [2]: 2 + 3 Out[2]:5 ⌨ Shift + Enter ⌨ Shift + Enter
Type code in a cell → press Shift + Enter → the output appears right below. Text cells (Markdown) hold notes and headings.

Anaconda is a free distribution that installs Python, Jupyter Notebook and hundreds of data-science libraries together. You can also use Google Colab in the browser without installing anything.

2. Virtual Environments and Packages

๐Ÿ“– Separate school bags

You don't carry your cricket kit in your school bag. A virtual environment is like a separate bag for each project: it keeps that project's Python version and libraries separate, so one project's packages don't clash with another's.

๐ŸŽ’ ai_practicalPython 3.10numpypandasmatplotlib ๐ŸŽฎ game_projectPython 3.8pygamenumpy (older) ๐Ÿ“ท cv_projectPython 3.11opencv-pythonnumpy
One virtual environment per project: each "bag" has its own Python version and packages, so an update in one never breaks another.
# Anaconda Prompt conda create -n myenv python=3.10 # create environment conda activate myenv # switch it on pip install numpy pandas matplotlib # install packages jupyter notebook # open Jupyter

3. Python Fundamentals

Variables and data types

name = "Riya" # str age = 15 # int height = 5.4 # float is_topper = True # bool print(name, type(age))
Riya <class 'int'>
strintfloatbool"Riya"155.4True
Every value has a type: text → str, whole number → int, decimal → float, True/False → bool.

Operators

TypeOperatorsExample (x = 7)
Arithmetic+ − * / // % **x // 2 = 3, x % 2 = 1, x ** 2 = 49
Comparison== != > < >= <=x > 5 → True
Logicaland, or, notx > 5 and x < 10 → True
Assignment= += -= *=x += 3 → x becomes 10

Input and output

city = input("Enter your city: ") print("Welcome to", city)

4. Decisions and Loops

temp = 38 if temp > 35: print("Hot day") elif temp > 25: print("Pleasant") else: print("Cool")
Hot day
๐ŸŒก️ Try it: move the slider and watch Python choose a path
temp > 35 ? temp > 25 ? print("Hot day") ๐Ÿฅต print("Pleasant") ๐Ÿ™‚ else: print("Cool") ๐Ÿฅถ YesNoYesNo
Hot day
# 5 times table, first five values for i in range(1, 6): print(i * 5, end=" ")
5 10 15 20 25
range(1,6) 12345 each turn: print(i * 5) Output ▸ 510152025
The loop visits 1, 2, 3, 4, 5 one by one (it stops before 6) and prints i × 5 each time.

▶ Watch a loop run, step by step (auto-play flowchart)

Press nothing — the flowchart runs by itself! Watch the yellow dot travel, the box that is working light up, and the variables change. Use the buttons to pause, go one step at a time, or switch between a for loop and a while loop.

Yes (True) No repeat ↺ Start
PYTHON CODE
VARIABLES (memory)
OUTPUT
✅ What the flowchart teaches

Every loop has 4 parts: ① start value (i = 1) → ② condition check (i ≤ 5?) → ③ body (the work) → ④ update (i = i + 1), then back to the check. When the condition becomes False, the loop stops. In a while loop, if you forget step ④, the condition never becomes False — that's an infinite loop!

⚠️ Common mistakes

1) Forgetting the colon : after if/for. 2) Wrong indentation — Python uses spaces to group code. 3) range(1, 6) stops at 5, not 6.

5. Lists and Built-in Functions

marks = [78, 92, 65, 92, 88] print(len(marks), max(marks), min(marks), sum(marks)) print("Average:", sum(marks) / len(marks)) marks.append(70) # add at end marks.sort() # arrange in ascending order
5 92 65 415 Average: 83.0
marks 78[0][-5]92[1][-4]65[2][-3]92[3][-2]88[4][-1] 70append
Blue = index from the left (starts at 0). Red = negative index from the right. marks.append(70) adds a new box at the end.
๐Ÿงช List playground — click a function to run it
marks = [78, 92, 65, 92, 88]
Click a button above
Built-in functionUse
print(), input()Show output / take input
len(), max(), min(), sum()Length, largest, smallest, total
type(), int(), float(), str()Check / convert data type
range(), round(), sorted()Number sequence, rounding, sorted copy

Mean, median, mode (a practical-file favourite)

import statistics as st marks = [78, 92, 65, 92, 88] print(st.mean(marks), st.median(marks), st.mode(marks))
83 88 92

6. Python Libraries for AI

๐Ÿ”ข

NumPy

Fast maths on arrays/matrices. import numpy as np

๐Ÿผ

Pandas

Read and analyse tables and CSV files. import pandas as pd

๐Ÿ“Š

Matplotlib

Draw line, bar, scatter and pie charts. import matplotlib.pyplot as plt

๐Ÿ“ท

OpenCV

Read, display and edit images. import cv2

# Read a CSV and draw a line chart import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("marks.csv") print(df.head()) # first 5 rows plt.plot(df["Test"], df["Marks"]) plt.title("My progress") plt.show()
My progress 60708090 T1T2T3T4T5 6270688188 plt.plot(df["Test"], df["Marks"]) draws this line
What plt.show() displays: the line draws from test to test, just like the code above.
# Read and show an image import cv2 img = cv2.imread("flower.jpg") print(img.shape) # (height, width, 3) → 3 = RGB channels
๐Ÿ’ป
No laptop at home? Open Google Colab on your phone or any computer, click "New notebook" and run every snippet above. NumPy, Pandas and Matplotlib are already installed there.

Viva Practice

Q1. What is the extension of a Jupyter Notebook file?

.ipynb

Q2. Why do we create a virtual environment?

To keep each project's Python version and packages separate and avoid clashes.

Q3. Which library is used to read CSV files?

Pandas — pd.read_csv()

Q4. Output of 7 // 2 and 7 % 2?

3 and 1

⚡ One-minute revision

  • Jupyter = cells (code + markdown), Shift+Enter runs, saved as .ipynb.
  • Virtual environment keeps project packages separate; install with pip install.
  • Data types: int, float, str, bool. Operators: arithmetic, comparison, logical, assignment.
  • if / elif / else for decisions; for / while for loops.
  • Lists + built-ins: len, max, min, sum, sorted, append.
  • Libraries: NumPy, Pandas, Matplotlib, OpenCV.

Done reading? Test yourself on AI Unit 7 in board-exam style.

๐Ÿ“ Take the Practice PaperNext: ES Unit 1 ›๐Ÿ  Class 10 Hub

Comments

๐Ÿงญ Explore AI Topics

Keep learning with our topic guides for CBSE AI (Classes 6–12).

๐Ÿ”„ AI Project Cycle๐Ÿ Python for AI๐Ÿค– Machine Learning๐Ÿ’ฌ NLP๐Ÿ‘️ Computer Vision⚖️ AI Ethics