FREE Live Master Session: Code Your AI Companion for Kids

    Register for Free →
    HomeClass 9 AI (417)Chapter 5: Python for AI
    Unit 5 · Subject Specific Skills50 Hours · 8 Marks · CBSE Curriculum

    Class 9 Introduction to Python – Artificial IntelligenceNotes, Questions from CBSE Curriculum, MCQs & Practical Programs

    Learn the foundational coding language for AI in CBSE Class 9. Covers variables, operators, data types, if-else conditions, loops, list manipulation, 25 practice MCQs, and 15 practical programs.

    Curriculum Study Guide

    Class 9 Python for AI Notes

    5.1

    Python Fundamentals for Artificial Intelligence

    Official Duration: 50 Hours · Variables, Operators, Flow of Control & Lists

    1. Variables & Naming Rules

    A variable is a named storage location in memory. In Python, variables are dynamically typed and created upon assignment.

    • Names can contain letters, digits, and underscores (_).
    • Names cannot begin with a digit (e.g., 1score is invalid).
    • Names are case-sensitive (Age and age are distinct).
    • Reserved keywords (such as if, for, class) cannot be used as variable names.

    2. Operators in Python

    Arithmetic Operators

    • + (Addition), - (Subtraction)
    • * (Multiplication), / (Float Division: 7/2 = 3.5)
    • // (Floor Division: 7//2 = 3)
    • % (Modulus Remainder: 7%2 = 1)
    • ** (Exponentiation: 2**3 = 8)

    Relational & Logical

    • == (Equal to), != (Not equal)
    • > (Greater than), < (Less than)
    • >= (Greater or equal), <= (Less or equal)
    • and (True if both conditions True)
    • or (True if at least one True)
    • not (Inverts boolean truth value)

    3. Flow of Control (Conditions & Loops)

    Conditionals (if-elif-else)

    Evaluates logical conditions. Indentation (4 spaces) is required to group code blocks.

    Loops (for & while)

    for iterates through sequences like range(1, 11); while iterates as long as a condition remains True.

    4. Python Lists

    Lists are ordered, mutable sequences enclosed in brackets. Elements support both positive indexing (0 to length - 1) and negative indexing (-1 from right). Slices follow list[start : stop] where stop is exclusive. Common methods include append(), extend(), insert(), remove(), pop(), and sort().

    Official Practical Programs

    Curriculum Programs from CBSE Class 9

    Core practical coding tasks prescribed in the Subject Code 417 syllabus with full copyable solutions and step-by-step logic.

    Curriculum Program 1Area and Perimeter of a Rectangle

    Write a Python program to take length and breadth as input from the user and calculate the area and perimeter of a rectangle.

    # Program 1: Area and Perimeter of Rectangle
    length = float(input("Enter length: "))
    breadth = float(input("Enter breadth: "))
    
    area = length * breadth
    perimeter = 2 * (length + breadth)
    
    print("Area of Rectangle:", area)
    print("Perimeter of Rectangle:", perimeter)

    Logic & Concepts: Uses float(input()) to accept decimal dimensions and applies basic arithmetic formulas.

    Curriculum Program 2Fahrenheit to Celsius Conversion

    Write a Python program to convert temperature from Fahrenheit to Celsius using formula: C = (F - 32) * 5/9.

    # Program 2: Fahrenheit to Celsius
    fahrenheit = float(input("Enter temperature in Fahrenheit: "))
    celsius = (fahrenheit - 32) * 5 / 9
    
    print("Temperature in Celsius:", round(celsius, 2))

    Logic & Concepts: Demonstrates operator precedence with parentheses and the built-in round() function.

    Curriculum Program 3Check Even or Odd Number

    Write a program to input an integer and check whether it is Even or Odd using the modulus operator.

    # Program 3: Even or Odd
    num = int(input("Enter an integer: "))
    
    if num % 2 == 0:
        print(num, "is an Even number.")
    else:
        print(num, "is an Odd number.")

    Logic & Concepts: Uses the modulus operator (%) to check divisibility by 2 with conditional branching.

    Curriculum Program 4Greatest of Three Numbers

    Write a Python program to find the largest among three distinct numbers entered by the user.

    # Program 4: Greatest of Three Numbers
    a = float(input("Enter first number: "))
    b = float(input("Enter second number: "))
    c = float(input("Enter third number: "))
    
    if a >= b and a >= c:
        largest = a
    elif b >= a and b >= c:
        largest = b
    else:
        largest = c
    
    print("The greatest number is:", largest)

    Logic & Concepts: Demonstrates logical 'and' operators combined with if-elif-else conditional branching.

    Curriculum Program 5Multiplication Table using for loop

    Write a Python program to print the multiplication table of a given number from 1 to 10.

    # Program 5: Multiplication Table
    num = int(input("Enter number for multiplication table: "))
    
    for i in range(1, 11):
        print(num, "x", i, "=", num * i)

    Logic & Concepts: Uses a for loop with range(1, 11) where the upper bound 11 is exclusive.

    Curriculum Program 6Positive and Negative List Slicing

    Given num = [23, 12, 5, 9, 65, 44], demonstrate positive indexing for 2nd to 4th element and negative indexing for 3rd to 5th element.

    # Program 6: List Indexing and Slicing
    num = [23, 12, 5, 9, 65, 44]
    print("List:", num)
    print("Length:", len(num))
    
    # Elements from 2nd to 4th position (index 1 to 3)
    pos_slice = num[1 : 4]
    print("2nd to 4th elements (positive index):", pos_slice)
    
    # Negative indexing slice
    start, end = -4, -1
    neg_slice = num[start : end]
    print("3rd to 5th elements (negative index):", neg_slice)

    Logic & Concepts: Demonstrates that positive indexing starts at 0 while negative indexing starts at -1 from the right.

    Exam Preparation

    Class 9 Python for AI MCQs

    25 targeted practice MCQs based on Python fundamentals, operators, conditionals, loops, and list manipulation.

    TeacherColab Practice MCQ #1
    5.1 Python VariablesEasy

    Which of the following is an INVALID variable name in Python?

    TeacherColab Practice MCQ #2
    5.1 input() Return TypeEasy

    What is the default data type returned by Python's built-in input() function?

    TeacherColab Practice MCQ #3
    5.1 Integer Floor DivisionMedium

    What is the output of the Python expression: 17 // 4?

    TeacherColab Practice MCQ #4
    5.1 Modulus OperatorEasy

    What is the result of the expression: 19 % 5?

    TeacherColab Practice MCQ #5
    5.1 Exponentiation OperatorEasy

    Which operator is used in Python to calculate powers (e.g., 2 to the power 3)?

    TeacherColab Practice MCQ #6
    5.1 String ConcatenationMedium

    What is the output of: print('Hello' * 3)?

    TeacherColab Practice MCQ #7
    5.1 Relational Operator EqualityEasy

    Which operator tests whether two values are equal in Python?

    TeacherColab Practice MCQ #8
    5.1 Logical OperatorsMedium

    What does the expression `(5 > 2) and (10 < 4)` evaluate to?

    TeacherColab Practice MCQ #9
    5.1 Indentation RulesEasy

    In Python, code blocks under if statements and loops are defined using:

    TeacherColab Practice MCQ #10
    5.1 range() Function Upper BoundMedium

    How many times will this loop execute: `for i in range(1, 6): print(i)`?

    TeacherColab Practice MCQ #11
    5.1 range() Step ArgumentMedium

    What sequence of numbers is produced by `list(range(2, 11, 2))`?

    TeacherColab Practice MCQ #12
    5.1 While Loop TerminationMedium

    What happens if the condition of a while loop never becomes False and no break statement is used?

    TeacherColab Practice MCQ #13
    5.1 List MutabilityEasy

    Unlike strings and tuples, Python lists are:

    TeacherColab Practice MCQ #14
    5.1 Negative IndexingEasy

    If colors = ['red', 'blue', 'green', 'yellow'], what does `colors[-1]` return?

    TeacherColab Practice MCQ #15
    5.1 List Slicing BoundariesMedium

    Given `nums = [10, 20, 30, 40, 50]`, what does the slice `nums[1 : 3]` evaluate to?

    TeacherColab Practice MCQ #16
    5.1 append() MethodEasy

    What is the effect of `items.append('pen')`?

    TeacherColab Practice MCQ #17
    5.1 len() FunctionEasy

    What does `len([5, 10, 15, 20])` return?

    TeacherColab Practice MCQ #18
    5.1 List remove() vs pop()Hard

    How does `list.remove(x)` differ from `list.pop(i)`?

    TeacherColab Practice MCQ #19
    5.1 Explicit TypecastingMedium

    What is the output of: `str(15) + str(25)`?

    TeacherColab Practice MCQ #20
    5.1 print() Separator ParameterMedium

    What will `print('AI', 'Class', '9', sep='-')` display?

    TeacherColab Practice MCQ #21
    5.1 Membership Operator 'in'Easy

    What does `'apple' in ['apple', 'banana', 'orange']` return?

    TeacherColab Practice MCQ #22
    5.1 Boolean Data TypeEasy

    Which of the following are valid Boolean literal values in Python?

    TeacherColab Practice MCQ #23
    5.1 Swapping VariablesMedium

    In Python, which elegant syntax swaps variables `x` and `y` without a temporary variable?

    TeacherColab Practice MCQ #24
    5.1 List sort() MethodMedium

    If `data = [40, 10, 30, 20]`, what does `data.sort()` do?

    TeacherColab Practice MCQ #25
    5.1 Practical Exam SchemeEasy

    In the CBSE Class 9 AI Practical Exam (Part C), how many coding programs must students execute during the examination?

    Subjective Prep

    Class 9 Python Questions and Answers

    Organized into Very Short, Short, and Long/Practical categories.

    Very Short Answer Questions (1 Mark Each)

    Question #1From the CBSE Curriculum

    Q: What is the difference between '=' and '==' in Python?

    Answer:

    '=' is the assignment operator used to assign a value to a variable. '==' is the comparison operator used to test equality between two expressions.

    Explanation: Core syntax covered in Unit 5 operators.

    Question #2From the CBSE Curriculum

    Q: What is the index of the first element and last element in a Python list?

    Answer:

    The first element has positive index 0. The last element has negative index -1.

    Explanation: Detailed in list indexing semantics.

    Question #3From the CBSE Curriculum

    Q: What function converts a numeric string into an integer in Python?

    Answer:

    The int() typecasting function (e.g., int('45') returns integer 45).

    Explanation: Required when handling numerical inputs from input().

    Short Answer Questions (2–3 Marks Each)

    Question #1From the CBSE Curriculum

    Q: Explain why Python indentation is mandatory and what happens if indentation is inconsistent.

    Answer:

    Python uses indentation (conventionally 4 spaces) rather than curly braces to define the structural blocks of code under if-else conditions, loops, and functions. If indentation is mismatched, Python raises an IndentationError and terminates execution.

    Explanation: Strict indentation ensures high code readability across Python programs.

    Question #2From the CBSE Curriculum

    Q: Differentiate between `/` (float division) and `//` (floor division) with examples.

    Answer:

    • `/` performs standard division and always returns a floating-point result (e.g., 7 / 2 evaluates to 3.5). • `//` performs floor division and truncates the fractional part, returning the mathematical integer quotient (e.g., 7 // 2 evaluates to 3).

    Explanation: Standard operator comparison tested in CBSE examinations.

    Question #3From the CBSE Curriculum

    Q: How does the `range()` function work in a Python `for` loop?

    Answer:

    The range(start, stop, step) function generates an immutable arithmetic sequence of integers starting at `start`, incrementing by `step`, and halting immediately before reaching the exclusive `stop` boundary.

    Explanation: Fundamental loop control mechanism in Class 9 AI.

    Long Answer & Program Walkthroughs (4–5 Marks Each)

    Question #1From the CBSE Curriculum

    Q: Explain how to separate positive and negative numbers from a single list into two distinct lists in Python.

    Answer:

    ```python # Input list numbers = [12, -7, 5, -3, -14, 25, 0, -2] positives = [] negatives = [] for n in numbers: if n >= 0: positives.append(n) else: negatives.append(n) print('Positive numbers:', positives) print('Negative numbers:', negatives) ``` Walkthrough: 1. Initialize two empty lists `positives` and `negatives`. 2. Iterate through each element in `numbers` using a `for` loop. 3. Check if the element is non-negative (`n >= 0`). If True, append to `positives`; otherwise append to `negatives`. 4. Output both lists.

    Explanation: Standard CBSE Practical Program 15 from the syllabus.

    Python Syntax Cheat Sheet

    Quick Revision: Unit 5 At a Glance

    Python Operators

    • Floor Division (//): Truncates decimal part (e.g., 9 // 2 = 4).
    • Modulus (%): Yields remainder (e.g., 9 % 2 = 1).
    • Exponent (**): Calculates power (e.g., 3 ** 2 = 9).
    • Equality (==): Tests value equivalence.

    List Indexing & Slicing

    • Positive Indexing: Starts at 0 from the left.
    • Negative Indexing: Starts at -1 from the right.
    • Slicing: list[start : stop] (stop is exclusive).
    • Length: len(list) returns total element count.

    Common List Methods

    • list.append(x): Adds element x to the end.
    • list.extend(iterable): Adds all items individually.
    • list.remove(x): Deletes first occurrence of x.
    • list.sort(): Sorts list ascending in place.

    Flow Control Rules

    • Indentation: 4 spaces define blocks under if/loops.
    • range(a, b): Includes a, halts before b.
    • input(): Always returns string type.
    Student FAQs & AEO

    Frequently Asked Questions

    🎓 Live 1-on-1 Classes

    Book a Free Demo Class

    Get personalised CBSE Class 9 AI coaching from expert educators. Interactive live sessions, doubt resolution, and exam preparation — tailored to your pace.