Unit 5: Introduction to Python Notes Class 9th Employability Skill Notes
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:
- Understanding the Problem – Know what needs to be solved
- Planning the Solution – Design how to solve it
- Coding – Write the actual program
- Testing – Check if it works correctly
- 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
Algorithm | Flowchart |
---|---|
Written in words | Uses shapes and symbols |
Text-based | Visual/Graphical |
Takes more time to understand | Easy to understand at a glance |
Difficult to debug | Easy to find errors |
5. Programming Language
Definition: A language used to communicate with computers.
Types:
- Low-level – Machine language (0s and 1s)
- 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
- Simple and Easy – Like writing in English
- Free – No cost to use
- Portable – Works everywhere
- Interpreted – Runs line by line
- Object-Oriented – Organizes code efficiently
- Large Library – Pre-written code available
Real-life Example: Like LEGO blocks – simple pieces that can build complex things!
8. Applications of Python
- Web Development – Instagram, YouTube
- Game Development – Minecraft uses Python
- Data Science – Weather prediction
- Artificial Intelligence – Siri, Alexa
- 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:
- Go to python.org
- Download latest version
- Run installer
- Check “Add to PATH”
- Click Install
- Verify by typing
python --version
in command prompt
11. Working in Python
Two Ways:
- Interactive Mode – Type and see results immediately
- 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:
- Keywords – Reserved words (if, else, for)
- Identifiers – Names we give (age, name)
- Literals – Fixed values (10, “Hello”)
- Operators – Symbols (+, -, *, /)
- Punctuators – Special symbols (:, ;, ,)
Real-life Example: Like words in a sentence – each has a specific role!
14. Data Types
Common Data Types:
- int – Whole numbers
age = 15
- float – Decimal numbers
height = 5.6
- str – Text
name = "Rahul"
- 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:
- Arithmetic: +, -, *, /, //, %, **
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- 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!)
- () – Parentheses
- ** – Exponent
- *, /, //, % – Multiplication, Division
- +, – – 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:
- Syntax Error – Wrong grammar
print("Hello" # Missing closing )
- Runtime Error – Error while running
x = 10/0 # Can't divide by zero
- Logical Error – Wrong logic
average = (a + b + c) / 2 # Should be /3
Quick Revision Tips:
- Practice Daily – Code for 30 minutes
- Start Small – Simple programs first
- Debug Errors – Learn from mistakes
- Use Comments – Explain your code
- 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.