Class 9th AI Notes – Unit 5: Introduction to Python

Part A: Employability Skills


1. Steps Involved in Computer Problem Solving

Computer problem solving follows a systematic approach:

  1. Understanding the Problem – Know what needs to be solved
  2. Planning the Solution – Design how to solve it
  3. Coding – Write the actual program
  4. Testing – Check if it works correctly
  5. Documentation – Write about what the program does

Real-life Example: Like making tea – first understand you need tea, plan ingredients, make it, taste it, and remember the recipe!


2. Algorithm

Definition: Step-by-step instructions to solve a problem, written in plain English.

Example Algorithm – Making a Sandwich:

Step 1: Take two bread slices
Step 2: Apply butter on one side of each slice
Step 3: Place vegetables on one slice
Step 4: Cover with the other slice
Step 5: Serve the sandwich

Characteristics:

  • Clear and unambiguous
  • Has a definite start and end
  • Each step is simple and executable

3. Flowchart

Definition: Visual representation of an algorithm using shapes and arrows.

Common Symbols:

  • Oval – Start/End
  • Rectangle – Process/Action
  • Diamond – Decision (Yes/No)
  • Arrow – Flow direction

Real-life Example: Like a map showing directions from home to school!


4. Difference between Algorithm and Flowchart

AlgorithmFlowchart
Written in wordsUses shapes and symbols
Text-basedVisual/Graphical
Takes more time to understandEasy to understand at a glance
Difficult to debugEasy to find errors

5. Programming Language

Definition: A language used to communicate with computers.

Types:

  1. Low-level – Machine language (0s and 1s)
  2. High-level – Human-readable (Python, Java)

Real-life Example: Like different languages humans speak – Hindi, English, etc. Computers understand programming languages!


6. What is Python?

Definition: Python is a simple, high-level programming language created by Guido van Rossum in 1991.

Why “Python”? Named after the comedy show “Monty Python’s Flying Circus”!

Key Points:

  • Easy to learn and read
  • Free and open-source
  • Works on all platforms (Windows, Mac, Linux)

7. Important Features of Python

  1. Simple and Easy – Like writing in English
  2. Free – No cost to use
  3. Portable – Works everywhere
  4. Interpreted – Runs line by line
  5. Object-Oriented – Organizes code efficiently
  6. Large Library – Pre-written code available

Real-life Example: Like LEGO blocks – simple pieces that can build complex things!


8. Applications of Python

  1. Web Development – Instagram, YouTube
  2. Game Development – Minecraft uses Python
  3. Data Science – Weather prediction
  4. Artificial Intelligence – Siri, Alexa
  5. Automation – Auto-sending emails

9. Role of Python in Artificial Intelligence

Python is the #1 language for AI because:

  • Simple syntax – Focus on logic, not language complexity
  • AI Libraries – TensorFlow, PyTorch ready to use
  • Community Support – Millions of developers help

Real-life Example: Like having a smart assistant that understands simple commands!


10. Installing Python

Steps:

  1. Go to python.org
  2. Download latest version
  3. Run installer
  4. Check “Add to PATH”
  5. Click Install
  6. Verify by typing python --version in command prompt

11. Working in Python

Two Ways:

  1. Interactive Mode – Type and see results immediately
  2. Script Mode – Write complete program and run

Example:

# Interactive Mode
>>> 2 + 3
5

# Script Mode - Save as file.py and run
print("Hello World")

12. Python Character Set

Characters Python understands:

  • Letters: A-Z, a-z
  • Digits: 0-9
  • Special Symbols: +, -, *, /, =, (), [], {}, etc.
  • Whitespace: space, tab, newline

13. Tokens

Definition: Smallest units in a Python program.

Types:

  1. Keywords – Reserved words (if, else, for)
  2. Identifiers – Names we give (age, name)
  3. Literals – Fixed values (10, “Hello”)
  4. Operators – Symbols (+, -, *, /)
  5. Punctuators – Special symbols (:, ;, ,)

Real-life Example: Like words in a sentence – each has a specific role!


14. Data Types

Common Data Types:

  1. int – Whole numbers
   age = 15
  1. float – Decimal numbers
   height = 5.6
  1. str – Text
   name = "Rahul"
  1. bool – True/False
   is_student = True

15. Variables

Definition: Containers to store data values.

Rules for Naming:

  • Start with letter or underscore
  • No spaces allowed
  • Case-sensitive (age ≠ Age)

Example:

# Good variable names
student_name = "Priya"
roll_number = 25
marks = 85.5

# Bad variable names
2name = "Wrong"  # Can't start with number
my-age = 15      # Can't use hyphen

16. The print() Function

Purpose: Display output on screen.

Examples:

# Simple print
print("Hello World")

# Print variables
name = "Amit"
print(name)

# Print multiple items
age = 14
print("I am", age, "years old")

17. The input() Function

Purpose: Take input from user.

Example:

# Taking input
name = input("Enter your name: ")
age = input("Enter your age: ")

# Convert to number
age = int(input("Enter your age: "))

18. Operators

Types:

  1. Arithmetic: +, -, *, /, //, %, **
  2. Comparison: ==, !=, >, <, >=, <=
  3. Logical: and, or, not
  4. Assignment: =, +=, -=, *=, /=

Examples:

# Arithmetic
result = 10 + 5  # 15

# Comparison
is_adult = age >= 18

# Logical
can_vote = is_adult and has_voter_id

19. Operator Precedence

Order of Operations: (Like BODMAS in Maths!)

  1. () – Parentheses
  2. ** – Exponent
  3. *, /, //, % – Multiplication, Division
  4. +, – – Addition, Subtraction

Example:

result = 2 + 3 * 4  # Answer: 14 (not 20)
result = (2 + 3) * 4  # Answer: 20

20. Comments in Python

Purpose: Notes for humans, ignored by computer.

Types:

# Single line comment

"""
Multi-line
comment
"""

Real-life Example: Like sticky notes on your notebook!


21. Statements in Python

Definition: Instructions that Python can execute.

Types:

# Expression statement
x = 5 + 3

# Assignment statement
name = "Rohit"

# Print statement
print("Hello")

22. Control Structures

Three types of program flow:

1. Sequential Statements

Execute line by line in order.

print("Step 1")  # Runs first
print("Step 2")  # Runs second
print("Step 3")  # Runs third

2. Selection Statements (Decision Making)

Choose which code to run.

if statement:

age = 16
if age >= 18:
    print("You can vote")
else:
    print("Too young to vote")

if-elif-else:

marks = 85
if marks >= 90:
    print("Grade A")
elif marks >= 80:
    print("Grade B")
else:
    print("Grade C")

3. Iterative Statements (Loops)

Repeat code multiple times.

for loop:

# Print numbers 1 to 5
for i in range(1, 6):
    print(i)

while loop:

# Count down from 5
count = 5
while count > 0:
    print(count)
    count = count - 1

23. Lists in Python

Definition: Collection of items in order.

Example:

# Creating lists
fruits = ["apple", "banana", "mango"]
marks = [85, 92, 78, 88]

# Accessing items
print(fruits[0])  # apple
print(marks[2])   # 78

# Adding items
fruits.append("orange")

# Length of list
print(len(fruits))  # 4

Real-life Example: Like a shopping list where you can add, remove, or check items!


24. Errors in Python

Common Types:

  1. Syntax Error – Wrong grammar
   print("Hello"  # Missing closing )
  1. Runtime Error – Error while running
   x = 10/0  # Can't divide by zero
  1. Logical Error – Wrong logic
   average = (a + b + c) / 2  # Should be /3

Quick Revision Tips:

  1. Practice Daily – Code for 30 minutes
  2. Start Small – Simple programs first
  3. Debug Errors – Learn from mistakes
  4. Use Comments – Explain your code
  5. Try Examples – Modify and experiment

Remember: Python is like learning a new language – practice makes perfect! 🐍


Discover more from EduGrown School

Subscribe to get the latest posts sent to your email.