MAHENDRA ENGINEERING COLLEGE
(Autonomous)
Syllabus
Computer Science and Program
Department 1041
Engineering Code
III Semester
Course Hours/Week Credit Maximum
Course Name
Code L T P C marks
PYTHON PROGRAMMING
24CS24301 0 0 3 1.5 100
LAB
The student should be made to:
● Learn python programs with conditionals and loops.
Objective(s): ● Understand compound data using Python lists, tuples, dictionaries
● Know python programs with functions.
● Learn files and exceptions in Python.
● Be familiar with modules in Python
Upon completion of this course, the Learners will be able to :
● Implement Python programs with conditionals and loops.
● Implement Python lists, tuples, dictionaries for representing compound
Outcome(s): data.
● Develop Python programs functions.
● Implement programs to files and exceptions in Python.
● Develop modules in Python
LIST OF EXERCISES
1 Print the below triangle using for loop in python.
5
44
333
2222
11111
2 Write a program to check whether the given input is digit or lowercase character or uppercase
character or a special character (use ‘if-else-if’ ladder)
3 Write a python program to print the Fibonacci sequence using while loop.
4 Write a program to create, append and remove lists in python
5 Write a program to demonstrate working with tuples in python
6 Write a program to add, change and remove elements in Dictionary
7 Write a python program for basic calculator operations using functions
8 Write a python program to find factorial of a number using recursion
9 Write a function called palindrome that takes a string argument and returns True if it is a
palindrome and False otherwise
10 Write a python program to read the file contents and do the following operations:
i) Print each word of a file in reverse order.
ii) Print each line of a file in reverse order.
Sample Input: Python Programming
Sample Output: Programming Python
iii) Display the content without whitespaces
Sample Output: Python Programming
11 Implementing real-time/technical applications using File handling. (copy from one file to
another, word count, longest word)
12 Implementing real-time/technical applications using Exception handling. (Divide by zero
error, voter’s age validity, student mark range validation)
13 Implementing programs using written modules and Python Standard Libraries (pandas,
NumPy.
14 Write a Python program to find the substrings within a string using re module
Total hours = 30 HOURS
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
State the Vision and Mission of the Department and Institute
Institute -Vision, Mission
Vision
To be an internationally recognized institute for engineering education and research with ethical
values
Mission
To ensure the effective use of resources to mould the students as professionals and entrepreneurs
To enhance the industry institute interaction for innovative technology practice
To encourage the faculty members and students for advanced research
To inculcate ethical values among the faculty members and students
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Department Vision , Mission
Vision
To produce competent computer engineers proficient with state of the art technologies
Mission
To impart good quality technical education through effective teaching-learning process
To enhance the students employability through mentoring and skill development
To promote innovation and research activities with analytical skills to face global challenges
To enable students imbibe ethical and enterprising characteristics to become socially responsible
engineers
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Program Educational Objectives (PEOs)
PEO1: Good communication, leadership and entrepreneurship skills
PEO2: Expertise on advanced computer technologies to become competitive
PEO3: The habit of learning and nurture the research attitude
PEO4:The ability to work in a team with professional ethics
Programme Specific Outcomes (PSOs)
The Graduates of Computer Science and Engineering shall have:
Ability to comprehend the underlying principles and systematic methods for the development,
operation and maintenance of software, using professional engineering practices.
Ability to develop socially acceptable technical solutions to real world problems with various
strategies for sustainable development.
Ability to apply the skills in the areas related to Algorithms, Networking, Web Designing, Artificial
Intelligence, Internet of Things and Data Analytics of various complexities towards successful
employment.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Program Outcomes (POs)
At the time of graduation, students from the Computer Science and Engineering program will possess:
Engineering Graduates will be able to:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health
and safety, and the cultural, societal, and environmental considerations
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modeling to complex engineering activities with an understanding of the
limitations
6. The Engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions
11. Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PYTHON PROGRAMMING LAB
LIST OF EXPERIMENTS
COURSE OUTCOMES (COs):
CO1: Implement Python programs using conditionals, loops, and functions to solve basic computational problems
CO2: Use Python data structures such as lists, tuples, and dictionaries to represent and manipulate compound data
CO3: Develop Python programs using files, exceptions, and modules for structured programming
[Link]. LIST OF EXPERIMENTS COs POs &PSOs
Print the below triangle using for loop in python.
5
44 PO1, PO5, PO9, PO12,
1. CO1
333 PSO1, PSO2, PSO3
2222
11111
Write a program to check whether the given input is
2. CO1 PO1, PO5, PO9, PO12,
digit or lowercase character or uppercase character or a
PSO1, PSO2, PSO3
special character (use 'if-else-if' ladder)
3. Write a python program to print the fibonacci sequence CO1 PO1, PO5, PO9, PO12,
using while loop PSO1, PSO2, PSO3
4. Write a program to create, append and remove lists in CO2 PO1, PO2, PO5, PO9, PO12,
python PSO1, PSO2, PSO3
5. Write a program to demonstrate working with tuples in CO2 PO1, PO2, PO5, PO9, PO12,
python PSO1, PSO2, PSO3
6. Write a program to to add,change and remove elements CO2 PO1, PO2, PO5, PO9, PO12,
in Dictionary PSO1, PSO2, PSO3
7. Write a python program for basic calculator operations CO2 PO1, PO2, PO5, PO9, PO12,
using functions PSO1, PSO2, PSO3
8. Write a python program to find factorial of a number CO2 PO1, PO2, PO5, PO9, PO12,
using recursion PSO1, PSO2, PSO3
Write a function called palindrome that takes a string PO1, PO2, PO5, PO9, PO12,
9. argument and returns True if it is a palindrome and CO2 PSO1, PSO2, PSO3
False otherwise.
Write a python program to read the file contents and do PO1, PO2, PO3, PO4, PO5,
the following operations: PO9, PO12, PSO1, PSO2,
i) Print each word of a file in reverse order. PSO3
ii) Print each line of a file in reverse order.
10 CO3
Sample Input: Python Programming
Sample Output: Programming Python
iii) Display the content without whitespaces
Sample Output: Python Programming
Implementing real-time/technical applications using File PO1, PO2, PO3, PO4, PO5,
11 handling. (copy from one file to another, word count, CO3 PO9, PO12, PSO1, PSO2,
longest word) PSO3
Implementing real-time/technical applications using PO1, PO2, PO3, PO4, PO5,
12 Exception handling. (divide by zero error, voter’s age CO3 PO9, PO12, PSO1, PSO2,
validity, student mark range validation) PSO3
PO1, PO2, PO3, PO4, PO5,
13 Implementing programs using written modules and CO3 PO9, PO12, PSO1, PSO2,
Python Standard Libraries (pandas, NumPy).
PSO3
PO1, PO2, PO3, PO4, PO5,
14 Write a Python program to find the substrings within a CO3 PO9, PO12, PSO1, PSO2,
string using re module
PSO3
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
SAFETY PRECAUTIONS IN THE LABORATORY
Know the location of the fire extinguisher and the first aid box and learn to use them in case of
an emergency
Report fires or accidents to your Faculty /Laboratory technician immediately
Report any broken plugs or exposed electrical wires to your Faculty/Laboratory technician
immediately
Do not insert metal objects such as clips, pins and needles into the computer casings
Do not touch, connect or disconnect any plug or cable without permission
Do not plug in external devices without scanning them for computer viruses
Always maintain an extra copy of all your important data files
Avoid stepping on electrical wires or any other computer cables
EXERCISE 1:
Write a program to print the below triangle using for loop in python.
5
44
333
2222
11111
AIM:
To Write and Execute a program to print the below triangle using for loop in python.
ALGORITHM:
STEP 1: Start
STEP 2: Set n = 5 (number of rows in the triangle)
STEP 3: Loop i from n down to 1 (i.e., 5 to 1):
STEP 4: For each row i, repeat printing the number i, (n - i + 1) times.
STEP 5: After printing each row, move to the next line.
STEP 6: End
PROGRAM:
n=5
for i in range(n, 0, -1):
for j in range(n - i + 1):
print(i, end=' ')
print()
OUTPUT:
5
44
333
2222
11111
RESULT:
Thus the program print the below triangle using for loop in python is executed successfully.
EXERCISE 2:
Write a program to check whether the given input is digit or lowercase character or uppercase
character or a special character (use ‘if-else-if’ ladder)
AIM:
To Write and Execute a program to check whether the given input is digit or lowercase character
or uppercase character or a special character (use ‘if-else-if’ ladder)
ALGORITHM:
STEP 1: Start the program.
STEP 2: Read a single character input from the user and store it in variable CH.
STEP 3: Check if CH is a digit.
Condition: If CH >= '0' and CH <= '9'
Then print "It is a Digit."
STEP 4: Else if CH is a lowercase character.
Condition: If CH >= 'a' and CH <= 'z'
Then print "It is a Lowercase Character."
STEP 5: Else if CH is an uppercase character.
Condition: If CH >= 'A' and CH <= 'Z'
Then print "It is an Uppercase Character."
STEP 6: Else Print "It is a Special Character."
STEP 7: Stop the program.
PROGRAM:
ch = input("Enter a single character: ")
if len(ch) != 1:
print("Please enter only a single character.")
else:
if ch >= '0' and ch <= '9':
print("It is a Digit.")
elif ch >= 'a' and ch <= 'z':
print("It is a Lowercase Character.")
elif ch >= 'A' and ch <= 'Z':
print("It is an Uppercase Character.")
else:
print("It is a Special Character.")
OUTPUT:
Enter a single character: G
It is an Uppercase Character.
Enter a single character: 9
It is a Digit.
Enter a single character: $
It is a Special Character.
Enter a single character: k
It is a Lowercase Character.
RESULT:
Thus the program to check whether the given input is digit or lowercase character or uppercase
character or a special character (use ‘if-else-if’ ladder) is executed Successfully.
EXERCISE 3:
Write a python program to print the Fibonacci sequence using while loop.
AIM:
To Write and Execute a program to print the Fibonacci sequence using while loop.
ALGORITHM:
STEP 1: Start
Initialize a ← 0, b ← 1, and count ← 0
STEP 2: Input n (number of terms)
Read n
STEP 3: If n ≤ 0, then
Print "Please enter a positive integer"
Go to Step 5
STEP 4: While count < n, do
Print a
Set next ← a + b
Set a ← b
Set b ← next
Increment count ← count + 1
STEP 5: Stop
PROGRAM:
a, b = 0, 1
count = 0
n = int(input("Enter the number of terms: "))
if n <= 0:
print("Please enter a positive integer.")
else:
print("Fibonacci sequence:")
while count < n:
print(a, end=' ')
a, b = b, a + b
count += 1
OUTPUT:
Enter the number of terms: 7
Fibonacci sequence:
0112358
RESULT:
Thus the program to print the Fibonacci sequence using while loop is executed Successfully.
EXERCISE 4:
Write a program to create, append and remove lists in python
AIM:
To Write and Execute a program to create, append and remove lists in python.
ALGORITHM:
STEP 1: Start
STEP 2: Create an empty list called my_list
STEP 3: Append elements (e.g., 10, 20, 30) to my_list
STEP 4: Remove specific elements (e.g., remove 20 by value, or remove first item
using index)
STEP 5: Display the final list and Stop
PROGRAM:
my_list = []
my_list.append(10)
my_list.append(20)
my_list.append(30)
print("List after appending:", my_list)
my_list.extend([40, 50])
print("List after extending:", my_list)
my_list.remove(20)
my_list.pop(0)
print("Final list after removals:", my_list)
OUTPUT:
List after appending: [10, 20, 30]
List after extending: [10, 20, 30, 40, 50]
Final list after removals: [30, 40, 50]
RESULT:
Thus the program to create, append and remove lists in python is executed successfully.
EXERCISE 5:
Write a program to demonstrate working with tuples in python
AIM:
To Write and Execute python program to demonstrate working with tuples in python.
ALGORITHM:
STEP 1: Start
STEP 2: Create a tuple with some elements
STEP 3: Access and display elements using indexing and slicing
STEP 4: Perform tuple operations like concatenation and repetition
STEP 5: Use tuple methods like count() and index()
STEP 6: Display the results
STEP 7: Stop
PROGRAM:
my_tuple = (10, 20, 30, 20, 40, 50)
print("First element:", my_tuple[0])
print("Elements from index 1 to 3:", my_tuple[1:4])
new_tuple = my_tuple + (60, 70)
print("Concatenated tuple:", new_tuple)
repeated_tuple = my_tuple * 2
print("Repeated tuple:", repeated_tuple)
count_20 = my_tuple.count(20)
index_30 = my_tuple.index(30)
print("Count of 20:", count_20)
print("Index of 30:", index_30)
OUTPUT:
First element: 10
Elements from index 1 to 3: (20, 30, 20)
Concatenated tuple: (10, 20, 30, 20, 40, 50, 60, 70)
Repeated tuple: (10, 20, 30, 20, 40, 50, 10, 20, 30, 20, 40, 50)
Count of 20: 2
Index of 30: 2
RESULT:
Thus the program to demonstrate working with tuples in python is executed successfully.
EXERCISE 6:
Write a program to add, change and remove elements in Dictionary
AIM:
To Write and Execute a python program to add, change and remove elements in Dictionary.
ALGORITHM:
STEP 1: Start
STEP 2: Create an empty dictionary
STEP 3: Add key-value pairs to the dictionary
STEP 4: Change the value of an existing key
STEP 5: Remove a key-value pair from the dictionary
STEP 6: Display the final dictionary
STEP 7: Stop
PROGRAM:
my_dict = {}
my_dict["name"] = "Alice"
my_dict["age"] = 25
my_dict["city"] = "New York"
print("Dictionary after adding elements:", my_dict)
my_dict["age"] = 30
print("Dictionary after changing age:", my_dict)
del my_dict["city"]
print("Dictionary after removing city:", my_dict)
OUTPUT:
Dictionary after adding elements: {'name': 'Alice', 'age': 25, 'city': 'New York'}
Dictionary after changing age: {'name': 'Alice', 'age': 30, 'city': 'New York'}
Dictionary after removing city: {'name': 'Alice', 'age': 30}
RESULT:
Thus the program to add, change and remove elements in Dictionary is executed Successfully.
EXERCISE 7:
Write a python program for basic calculator operations using functions
AIM:
To write a python program for basic calculator operations using functions.
ALGORITHM:
STEP 1:Start
STEP 2:Define functions for:
Addition
Subtraction
Multiplication
Division
STEP 3:Ask the user to enter two numbers.
STEP 4:Display a menu of operations (add, subtract, multiply, divide).
STEP 5:Ask the user to choose an operation.
STEP 6:Call the corresponding function based on the user's choice.
STEP 7:Display the result.
STEP 8:End
PROGRAM:
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Error! Cannot divide by zero."
return x / y
print("Basic Calculator")
print("Select Operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print("Result:", add(num1, num2))
elif choice == '2':
print("Result:", subtract(num1, num2))
elif choice == '3':
print("Result:", multiply(num1, num2))
elif choice == '4':
print("Result:", divide(num1, num2))
else:
print("Invalid input")
OUTPUT:
Basic Calculator
Select Operation:
1. Add
2. Subtract
3. Multiply
4. Divide
Enter choice (1/2/3/4): 1
Enter first number: 10
Enter second number: 5
Result: 15.0
RESULT:
Thus the program for basic calculator operations using functions is executed Successfully.
EXERCISE 8:
Write a python program to find factorial of a number using
recursion
AIM:
To write and Execute a program to find factorial of a number using recursion.
ALGORITHM:
STEP 1: Start
STEP 2: Define a recursive function factorial(n):
If n == 0 or n == 1, return 1 (base case).
Else, return n * factorial(n - 1).
STEP 3:Ask the user to enter a number.
STEP 4: Call the factorial() function with the input number.
STEP 5: Display the result.
STEP 6: End
PROGRAM:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
num = int(input("Enter a number to find factorial: "))
if num < 0:
print("Factorial is not defined for negative numbers.")
else:
print("Factorial of", num, "is", factorial(num))
OUTPUT:
Enter a number to find factorial: 5
Factorial of 5 is 120
RESULT:
Thus the program to find factorial of a number using recursion is executed successfully.
EXERCISE 9:
Write a function called palindrome that takes a string argument and returns True if it is a
palindrome and False otherwise
AIM:
To write and Execute a function called palindrome that takes a string argument and returns True if it is
a palindrome and False otherwise
ALGORITHM:
STEP 1: Start the program.
STEP 2: Define a function palindrome(s):
Convert the string to lowercase (to ignore case).
Remove spaces or non-alphanumeric characters if needed (optional).
Reverse the string.
Compare the original and reversed string.
If they are the same, return True.
Else, return False.
STEP 3: In the main program, take input from the user.
STEP 4: Call the palindrome() function with the input string.
STEP 5: Display the result.
STEP 6: Stop the program.
PROGRAM:
def palindrome(s):
s = [Link]()
s = [Link](" ", "")
return s == s[::-1]
word = input("Enter a string: ")
if palindrome(word):
print("It is a palindrome.")
else:
print("It is not a palindrome.")
OUTPUT:
Enter a string: madam
It is a palindrome.
RESULT:
Thus the program to a function called palindrome that takes a string argument and returns True if it is a
palindrome and False otherwise is executed successfully.
EXERCISE 10:
Write a python program to read the file contents and do the following operations:
i) Print each word of a file in reverse order.
ii) Print each line of a file in reverse order.
Sample Input: Python Programming
Sample Output: Programming Python
iii) Display the content without whitespaces
Sample Output: Python Programming
AIM:
To write a Python program to read the file contents and do the following operations.
a) Print each word of a file in reverse order.
b) Print each line of a file in reverse order.
c) Display the content without whitespaces.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Take the file from the user.
STEP 3: Read the lines in the file.
STEP 4: Print the elements of list in reverse order.
STEP 5: Print the Result.
STEP 6: Stop the program.
PROGRAM:
a)PRINT EACH WORD OF A FILE IN REVERSE ORDER
file = open("[Link]", "r")
for line in file:
words = [Link]()
for word in words:
print(word[::-1], end=' ')
print()
[Link]()
b)PRINT EACH LINE OF A FILE IN REVERSE ORDER
file = open("[Link]", "r")
for line in file:
words = [Link]().split()
reversed_line = " ".join(reversed(words))
print(reversed_line)
[Link]()
c)DISPLAY THE CONTENT WITHOUT WHITESPACES
file = open("[Link]", "r")
content = [Link]()
print("".join([Link]()))
[Link]()
OUTPUT:
a) Each word in reverse order:
nohtyP gnimmargorP
si nuf
b) Each line in reverse word order:
Programming Python
fun is
c) Content without whitespaces:
PythonProgrammingisfun
RESULT:
Thus the program to read the file contents and do the following operations.
a) Print each word of a file in reverse order.
b) Print each line of a file in reverse order.
c) Display the content without whitespaces are executed Successfully.
EXERCISE 11
Implementing real-time/technical applications using File handling. (copy from one file to another,
word count, longest word)
AIM:
To Write and Execute a program to demonstrate file handling by copying contents, counting
words, and finding the longest word.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Open source file in read mode and destination file in write mode.
STEP 3: Copy the contents from the source to the destination.
STEP 4: Read content into a list of words.
STEP 5: Count the number of words.
STEP 6: Use a loop or max() to find the longest word.
STEP 7: Print word count and longest word.
STEP 8: Stop the program.
PROGRAM:
# File handling and word analysis
with open("[Link]", "r") as src:
content = [Link]()
with open("[Link]", "w") as dst:
[Link](content)
words = [Link]()
print("Word count:", len(words))
print("Longest word:", max(words, key=len))
OUTPUT:
Word count: 12
Longest word: programming
RESULT:
Thus, the program for file handling applications like copying, word count, and finding the
longest word is executed successfully.
EXERCISE 12
Implementing real-time/technical applications using Exception handling. (divide by zero error,
voter’s age validity, student mark range validation)
AIM:
To Write and Execute a program to demonstrate exception handling for divide-by-zero, voter age
validation, and student mark validation.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Accept values for division and apply try-except to catch divide-by-zero.
STEP 3: Accept age input and validate if it is 18 or more.
STEP 4: Accept marks and check if they lie in range 0–100.
STEP 5: Print appropriate messages for valid or invalid input.
STEP 6: Handle exceptions using custom error messages.
STEP 7: Stop the program
PROGRAM:
# Divide by zero
try:
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
print("Result:", a / b)
except ZeroDivisionError:
print("Cannot divide by zero")
# Age check
age = int(input("Enter age: "))
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
# Marks validation
marks = int(input("Enter marks: "))
if 0 <= marks <= 100:
print("Valid marks")
else:
print("Invalid marks")
OUTPUT:
Result: 4.0
Eligible to vote
Valid marks
RESULT:
Thus, the program for exception handling in real-world scenarios is executed successfully.
EXERCISE 13
Implementing programs using written modules and Python Standard Libraries (pandas, NumPy).
AIM:
To Write and Execute programs using Python standard libraries such as NumPy and Pandas for
data processing and manipulation.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Import pandas and numpy libraries.
STEP 3: Use numpy to create and manipulate arrays.
STEP 4: Use pandas to create DataFrames and display tabular data.
STEP 5: Perform basic operations like selection, filtering, and display.
STEP 6: Stop the program.
PROGRAM:
# Using numpy and pandas
import numpy as np
import pandas as pd
a = [Link]([1, 2, 3])
print("NumPy Array:", a)
df = [Link]({'Name': ['Tom', 'Jerry'], 'Age': [20, 21]})
print("Pandas DataFrame:\n", df)
OUTPUT:
NumPy Array: [1 2 3]
Pandas DataFrame:
Name Age
0 Tom 20
1 Jerry 21
RESULT:
Thus, the program using Python libraries NumPy and Pandas is executed successfully.
EXERCISE 14
Write a Python program to find the substrings within a string using re module
AIM:
To Write and Execute a Python program to extract substrings using regular expressions
(re module).
ALGORITHM:
STEP 1: Start the program.
STEP 2: Import the re module for regular expressions.
STEP 3: Define a string and a pattern to search for.
STEP 4: Use [Link]() to find all matching substrings.
STEP 5: Print the matches found.
STEP 6: Stop the program.
PROGRAM:
# Regular expression to find substrings
import re
text = "Python exercises, PHPexercises"
pattern = r"exercises"
matches = [Link](pattern, text)
for match in matches:
print("Found:", match)
OUTPUT:
Found: exercises
Found: exercises
RESULT:
Thus, the program to find substrings using the re module is executed successfully.