Curriculum
Course: Grade IX AI(417)
Login
Text lesson

Unit 5-Introduction to Python

School Revise · Class 9 Artificial Intelligence · Unit 5

Introduction to Python

Code 417, Class 9. Python is the language of AI. Here we write our first programs and use variables, decisions and loops.

Python

the AI language

print

shows output

What this unit is about

Python is simple and readable, and AI is built with it. We print output, store values, and use decisions and loops.

1. print, variables, data types

print() shows output and a variable stores a value. Data types are int (whole numbers), float (decimals), str (text) and bool (True or False).

name = “AI” print(“Hello,”, name) Output: Hello, AI

2. Operators and input

Operators include + – * / and % (remainder). input() reads text from the user, and int(input()) reads a number.

3. Decisions and loops

if and else make decisions, and for and while loops repeat work, indented by four spaces.

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 welcome message.

SOLUTION

print(“Welcome to AI”)

OUTPUT

Welcome to AI
Problem 2. Store two numbers and print their sum.

SOLUTION

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

OUTPUT

8
Problem 3. Print the data type of 3.14.

SOLUTION

print(type(3.14))

OUTPUT

<class ‘float’>
Problem 4. Find the remainder of 17 divided by 5.

SOLUTION

print(17 % 5)

OUTPUT

2
Problem 5. Check if 8 is even.

SOLUTION

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

OUTPUT

even
Problem 6. Print the numbers 1 to 5.

SOLUTION

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

OUTPUT

1 2 3 4 5
Problem 7. Find the sum of 1 to 10.

SOLUTION

s = 0 for i in range(1, 11): s = s + i print(s)

OUTPUT

55
Problem 8. Make a list and print its sum.

SOLUTION

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

OUTPUT

60
Problem 9. Greet the user by name.

SOLUTION

name = input(“Your name: “) print(“Hello,”, name)

OUTPUT

Your name: Ravi Hello, Ravi
Problem 10. Print the average of 82, 91 and 76.

SOLUTION

print((82 + 91 + 76) / 3)

OUTPUT

83.0

Practice set A, multiple choice

1. Which function shows output?

print().

2. The data type of 3.14 is …

float.

3. What does 17 % 5 give?

2, the remainder.

4. Which function reads user input?

input().

Quick summary

Python is the language of AI. print() shows output, a variable stores a value, and data types are int, float, str and bool. Operators include + – * / and %. input() reads text (int(input()) reads a number). if and else make decisions, and for and while loops repeat work.

Open the Virtual Lab

These free Class 9 Artificial Intelligence (Code 417) notes explain an introduction to Python for AI, print variables and data types, operators and input, and decisions and loops 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 9 Artificial Intelligence syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories