PYTHON PROGRAMMING
PYTHON PROGRAMMING
Ἲ Objective:
By the end of this class, students will:
• Understand what Python is and where it’s used.
• Know why Python is a popular language.
• Be able to install Python and an IDE.
• Run their first Python program.
Ὅ Theory Part
✅ 1. What is Python?
Python is a high-level, interpreted, general-purpose programming language.
It was created by Guido van Rossum and released in 1991.
✅ Key Features of Python:
• Simple and Easy to Learn (English-like syntax)
• Free and Open Source
• Cross-platform or Portable (Works on Windows, Mac, Linux)
• Huge Community Support
• Interpreted Language (No need to compile)
• Object-Oriented and Procedural
• Wide Range of Libraries and Frameworks (for AI, Web Dev, and Data Science)
✅ 2. Where is Python Used?
• Web Development – Flask, Django
• Data Science & AI – Pandas, NumPy, TensorFlow
• Automation/Scripting – Automate boring tasks
• Cybersecurity – Ethical hacking scripts
• Game Development – Pygame
• Desktop Applications – Tkinter, PyQt
Ὃ Practical Part
✅ Step 1: Installing Python
ὑ Download Link:
ὄ https://www.python.org/downloads/
ὒ Installation Steps:
1. Go to the website.
2. Click "Download Python [Latest Version]".
3. IMPORTANT: Check the box that says ✅ Add Python to PATH.
4. Click Install Now.
5. After installation, open Command Prompt / Terminal and type:
python --version
print("Hello, Python!")
• Hit F5 to run.
ὓ Using VS Code or Text Editor:
1. Open a new file first_program.py.
2. Write:
python first_program.py
Small Task:
• Ask students to write three lines:
Ὅ Theory Part
✅ 1. Python Syntax
Syntax means the structure or rules that define how we write Python code.
Basic Structure Example:
print("Hello, world!")
# This is a comment
print("Hello!") # This prints Hello
'''
This is a multi-line comment.
It can span multiple lines.
'''
print("Python is awesome!")
Ὅ Note: Multi-line strings (''' or """) are not technically comments but can be used like
them.
✅ 3. Indentation in Python
• Indentation = Spaces or tabs at the beginning of a line
• Python uses indentation instead of curly braces to define blocks of code.
Example:
if 5 > 2:
print("5 is greater than 2")
Ὃ Practical Part
✅ 1. Print Practice (Syntax)
print("Good Morning!")
print("Today we're learning Python Syntax")
• Try running these and intentionally make some mistakes like missing quotes or
parentheses to show errors.
✅ 2. Comments Demo
'''
This is a multi-line comment
describing the purpose of the code
'''
print("Comments make code readable")
Ὂ Tip: Ask students to write a short paragraph in comments about why they want to
learn Python.
✅ 3. Indentation Examples
✅ Correct:
if 10 > 5:
print("10 is greater")
print("This is indented correctly")
if 10 > 5:
print("This will cause an error") # No indentation
ᾞ Class Activities
ὓ Activity 1: Syntax Challenge
Ask students to correct this code:
print"Hello students"
Correct Answer:
print("Hello students")
if 7 > 3:
print("Yes, it is")
print("Indentation is cool!")
Ὅ Theory Part
✅ 1. What is a Variable?
• A variable is a name that stores a value.
• It acts like a container to hold data in memory.
Example:
name = "Ali"
age = 18
Examples:
✅ Valid: user_name, marks1, _value
❌ Invalid: 1name, my-name, print
Ὃ Practical Part
✅ 1. Declaring Variables and Printing
name = "Sara"
age = 20
height = 5.6
is_student = True
print(name)
print(age)
print(height)
print(is_student)
print(type(name)) # str
print(type(age)) # int
print(type(height)) # float
print(type(is_student)) # bool
score = 50
print(score)
x = 10 # int
print(type(x))
x = "Ten" # str
print(type(x))
ᾞ Class Activities
ὓ Activity 1: Declare and Display
Ask students to create and print 3 variables:
• full_name
• age
• grade
ὓ Activity 2: Data Type Detective
Ask them to write 5 variables with different data types and use type() to check each one.
ὓ Activity 3: Update and Compare
fruit = "Apple"
print(fruit)
fruit = "Mango"
print(fruit)
x = True
print(type(x))
Homework
• Create 5 variables: name, city, age, marks, is_passed.
• Print each one and also print its type.
• Write one line about what you learned today using a comment.
a = 31
print(type(a)) #output --> class <int>
Type casting means a number can be converted into string and vice versa (If possible).
there are many functions to convert one data type into another.
a = 31
b = str(a)
print(b)
print(type(b))
Example:
This program takes the user’s name as input and prints a greeting.
Practice Programs:
1. Write a program that asks the user for their favorite food and prints it.
1. Create a program that asks for the user’s name and age, then prints them.
2. Write a program that takes two numbers as input and prints their sum.
Example Questions:
1. How do you take input from a user in Python?
2. Write a program that asks for the user’s favorite color and prints it.
3. What function do you use to display output in Python?
4. How do you combine text and variables in the print() function?
5. Write a program that takes your name and age as input and prints them.