0% found this document useful (0 votes)
3 views

PYTHON PROGRAMMING

The document provides an overview of Python programming, covering its definition, installation process, and key features. It includes practical exercises for students to write their first Python program, understand syntax, comments, indentation, variables, data types, and input/output functions. Additionally, it outlines classroom activities and homework assignments to reinforce learning.

Uploaded by

misbahjfr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PYTHON PROGRAMMING

The document provides an overview of Python programming, covering its definition, installation process, and key features. It includes practical exercises for students to write their first Python program, understand syntax, comments, indentation, variables, data types, and input/output functions. Additionally, it outlines classroom activities and homework assignments to reinforce learning.

Uploaded by

misbahjfr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PYTHON PROGRAMMING NOTES - Week 2

What is Python? Installing Python & IDEs

Ἲ 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

5. You should see a version like Python 3.11.6.


✅ Step 2: Installing IDE (Integrated Development Environment)
You can use any one of the following:
ὓ IDLE (comes with Python):
• Simple and easy to start
• Open it from Start Menu → Python → IDLE
ὓ VS Code (Recommended for later):
ὄ Download: https://code.visualstudio.com
• Lightweight and modern
• Has extensions for Python
✅ Set Up Python Extension in VS Code:
1. Open VS Code.
2. Click on Extensions (square icon on left sidebar).
3. Search Python, and install the one by Microsoft.
4. Create a new file with .py extension (e.g., hello.py).
✅ Step 3: Write Your First Python Program
ὓ Using IDLE:

print("Hello, Python!")

• Hit F5 to run.
ὓ Using VS Code or Text Editor:
1. Open a new file first_program.py.
2. Write:

print("Welcome to Python Programming!")

Save and run it from the terminal using:

python first_program.py

ὐ Classroom Activities / Practice


1. Ask students to introduce themselves using:

print("Hi, my name is Ali.") # Replace with their name

Small Task:
• Ask students to write three lines:

print("My name is ___")


print("I am learning Python.")
print("It's fun!")

Doubt check: Run a quiz


• What is an IDE?
• What is Python used for?
• What command checks the installed version?

Python Syntax, Comments, and Indentation


Ἲ Objective:
By the end of this class, students will:
• Understand the structure of a basic Python program.
• Use comments effectively.
• Learn why indentation is important in Python.
• Write simple code using proper syntax, comments, and indentation.

Ὅ Theory Part
✅ 1. Python Syntax
Syntax means the structure or rules that define how we write Python code.
Basic Structure Example:

print("Hello, world!")

• Every Python statement must follow indentation and syntax rules.


• Python does not use {} brackets or ; like other languages. It uses indentation.
✅ 2. Comments in Python
Comments are lines that are not executed by Python. They help explain what the code does.
ὓ Types of Comments:
✅ Single-Line Comment:

# This is a comment
print("Hello!") # This prints Hello

✅ Multi-Line Comment (using triple quotes):

'''
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")

• If you skip indentation, Python will show an IndentationError.

Ὃ 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 my first comment


print("Learning comments") # This line prints something

'''
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")

❌ Incorrect (will cause an error):

if 10 > 5:
print("This will cause an error") # No indentation

Try this live and show the IndentationError to make it visual.

ᾞ Class Activities
ὓ Activity 1: Syntax Challenge
Ask students to correct this code:

print"Hello students"

Correct Answer:
print("Hello students")

ὓ Activity 2: Comment Exercise


Ask students to write:
• A line with a single-line comment
• A block with a multi-line comment
• A print statement after that
ὓ Activity 3: Indentation Practice
Ask students to write:

if 7 > 3:
print("Yes, it is")
print("Indentation is cool!")

Homework / Extra Practice:


1. Write 3 print statements with comments above them.
2. Write a small if statement with 2 indented print lines.
3. Write a multi-line comment about why Python is easy to learn.

Variables, Data Types, type() function, Type casting &


Input() & Output function
Ἲ Objective:
By the end of this class, students will:
• Understand what variables are and how to use them.
• Learn about different data types in Python.
• Store, update, and print values using variables.
• Practice with real-time examples using variables and data types.

Ὅ 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

Here, name is storing "Ali", and age is storing 18.

✅ 2. Rules for Naming Variables


• Use letters, numbers, and underscores.
• It must start with a letter or underscore, not a number.
• Case-sensitive (Name ≠ name)
• Avoid using Python keywords like if, while, print as variable names.

Examples:
✅ Valid: user_name, marks1, _value
❌ Invalid: 1name, my-name, print

✅ 3. Python Data Types


Data Type Example Description int 10, -5 Whole numbers float 3.14, -0.5 Decimal numbers
str "Hello", 'Python' Text bool True, False Boolean values None None Represents no value

Ὃ 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)

✅ 2. Checking Data Types with type()

print(type(name)) # str
print(type(age)) # int
print(type(height)) # float
print(type(is_student)) # bool

✅ 3. Changing Variable Values

score = 50
print(score)

score = 75 # updating value


print(score)

✅ 4. Dynamic Typing in Python


Python allows variables to change type:

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)

Ask: What changed and why?


ὓ Quick Quiz (Ask Orally)
1. What is a variable?
2. Can variable names start with a number?
3. What’s the output of:

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.

Type() function & type casting


Type function is used to find the data type of a variable name.

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))

Input and Output


• Input: You can take input from the user using the input() function.

name = input("Enter your name: ")

• Output: You can display output using the print() function.


print("Hello", name)

Example:

name = input("What is your name? ")


print("Hello, " , name)

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.

name = input("Enter your name: ")


age = input("Enter your age: ")
print("Your name is", name, "and you are", age, "years old.")

food = input("What is your favorite food? ")


print("Your favorite food is:", food)

2. Write a program that takes two numbers as input and prints their sum.

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
print("The sum is:", num1 + num2)

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.

You might also like