Curriculum
Course: Grade XI AI
Login
Text lesson

Unit 3-Python Programming

School Revise · Class 11 Artificial Intelligence · Unit 3

Python Programming

Code 843, Class 11. Python is the language of AI. Here we write programs, use control statements, and meet the NumPy and Pandas libraries.

Python

the AI language

NumPy

arrays of numbers

What this unit is about

Python is simple and powerful, and AI is built with it. We print output, store data, make decisions and loops, and use libraries like NumPy and Pandas.

1. Basics and control statements

print() shows output and a variable stores a value. if and else make decisions, and for and while loops repeat work.

for i in range(1, 4): print(i) Output: 1 2 3

2. NumPy

NumPy works with arrays of numbers. import numpy as np; a = np.array([1, 2, 3]); and a.sum() adds them. NumPy is fast for the maths that AI needs.

3. Pandas

Pandas handles data in tables. A Series is a labelled column and a DataFrame is a table, used to load and study data before training a model.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Print a message.

SOLUTION

print(“Hello, AI”)

OUTPUT

Hello, AI
Problem 2. Store two numbers and print their sum.

SOLUTION

a = 5 b = 3 print(a + b)

OUTPUT

8
Problem 3. Print whether 8 is even.

SOLUTION

n = 8 if n % 2 == 0: print(“even”) else: print(“odd”)

OUTPUT

even
Problem 4. Print the numbers 1 to 5.

SOLUTION

for i in range(1, 6): print(i)

OUTPUT

1 2 3 4 5
Problem 5. Make a list and print its sum.

SOLUTION

nums = [10, 20, 30] print(sum(nums))

OUTPUT

60
Problem 6. Make a NumPy array and add it.

SOLUTION

import numpy as np a = np.array([1, 2, 3, 4]) print(a.sum())

OUTPUT

10
Problem 7. Find the mean with NumPy.

SOLUTION

import numpy as np a = np.array([2, 4, 6]) print(a.mean())

OUTPUT

4.0
Problem 8. Make a Pandas Series.

SOLUTION

import pandas as pd s = pd.Series([10, 20, 30]) print(s.tolist())

OUTPUT

[10, 20, 30]
Problem 9. Make a Pandas DataFrame.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 90]}) print(df[“marks”].mean())

OUTPUT

85.0
Problem 10. Read a value from the user.

SOLUTION

n = int(input(“Enter a number: “)) print(“You entered”, n)

OUTPUT

Enter a number: 7 You entered 7

Practice set A, multiple choice

1. Which function shows output?

print().

2. Which library works with arrays of numbers?

NumPy.

3. Which library handles data in tables?

Pandas.

4. A labelled column in Pandas is a …

Series.

Quick summary

Python is the language of AI. print() shows output, variables store values, and if, for and while control the flow. NumPy works with arrays of numbers and is fast for maths (a.sum(), a.mean()). Pandas handles data in tables: a Series is a labelled column and a DataFrame is a table, used to load and study data before training a model.

Open the Virtual Lab

These free Class 11 Artificial Intelligence (Code 843) notes explain Python programming for AI, basics and control statements, and the NumPy and Pandas libraries with clear examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 11 Artificial Intelligence syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories