0% found this document useful (0 votes)
3 views5 pages

Sample Lab Programs

The document outlines various Python programs across different sections, including simple interest calculation, odd/even number checking, factorial computation, linear search, and palindrome verification. It also covers data science applications using NumPy and Matplotlib for array manipulations, statistical measures, and plotting, as well as computer vision tasks with OpenCV for image processing. Additionally, it discusses natural language processing projects involving string tokenization and stop word filtering, along with a practical machine learning project using Google's Teachable Machine.

Uploaded by

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

Sample Lab Programs

The document outlines various Python programs across different sections, including simple interest calculation, odd/even number checking, factorial computation, linear search, and palindrome verification. It also covers data science applications using NumPy and Matplotlib for array manipulations, statistical measures, and plotting, as well as computer vision tasks with OpenCV for image processing. Additionally, it discusses natural language processing projects involving string tokenization and stop word filtering, along with a practical machine learning project using Google's Teachable Machine.

Uploaded by

Bincy Jolly
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SECTION 1: ADVANCED PYTHON PROGRAMS

Program 1: Simple Interest Calculation


 Aim: Write a Python program to calculate Simple Interest based on user inputs.
 Source Code:
python
p = float(input("Enter Principal amount: "))
r = float(input("Enter Rate of Interest: "))
t = float(input("Enter Time period (years): "))

si = (p * r * t) / 100
print("The Simple Interest is:", si)
Use code with caution.
 Output:
text
Enter Principal amount: 5000
Enter Rate of Interest: 5
Enter Time period (years): 2
The Simple Interest is: 500.0
Use code with caution.
Program 2: Odd or Even Number Checker
 Aim: Write a Python program to check if an entered number is odd or even.
 Source Code:
python
num = int(input("Enter any integer: "))
if num % 2 == 0:
print(num, "is an Even number.")
else:
print(num, "is an Odd number.")
Use code with caution.
Program 3: Factorial of a Number
 Aim: Write a Python program to find the factorial of a number using a loop.
 Source Code:
python
num = int(input("Enter a positive integer: "))
factorial = 1

if num < 0:
print("Factorial does not exist for negative numbers.")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1, num + 1):
factorial = factorial * i
print("The factorial of", num, "is", factorial)
Use code with caution.
Program 4: Linear Search in a List
 Aim: Search for an item inside a python list sequentially.
 Source Code:
python
numbers = [12, 45, 67, 89, 34, 56, 90]
target = int(input("Enter number to search: "))
found = False

for i in range(len(numbers)):
if numbers[i] == target:
print(f"Element found at index position {i}")
found = True
break

if not found:
print("Element not found in the list.")
Use code with caution.
Program 5: Palindrome String Verification
 Aim: Check if a user-provided word reads the same backward as forward.
 Source Code:
python
string = input("Enter a word: ").lower()
if string == string[::-1]:
print("The word is a palindrome.")
else:
print("The word is not a palindrome.")
Use code with caution.

SECTION 2: DATA SCIENCE (NUMPY & MATPLOTLIB)

Program 6: Array Manipulations using NumPy

 Aim: Create a 1D and 2D array matrix and print its structural shape attributes.
 Source Code:
python
import numpy as np

arr1 = [Link]([1, 2, 3, 4, 5])


arr2 = [Link]([[1, 2, 3], [4, 5, 6]])

print("1D Array:\n", arr1)


print("Shape of 1D Array:", [Link])
print("\n2D Array:\n", arr2)
print("Shape of 2D Array:", [Link])
Use code with caution.
Program 7: Basic Statistical Measures
 Aim: Calculate Mean, Median, and Mode of an array distribution.
 Source Code:
python
import numpy as np
from scipy import stats

data = [10, 20, 20, 30, 40, 50, 20, 60, 70]

mean_val = [Link](data)
median_val = [Link](data)
mode_val = [Link](data, keepdims=True).mode[0]

print("Dataset:", data)
print("Mean:", mean_val)
print("Median:", median_val)
print("Mode:", mode_val)
Use code with caution.
Program 8: Line Plot Generation via Matplotlib
 Aim: Plot line data tracking progression trends.
 Source Code:
python
import [Link] as plt

years = [2021, 2022, 2023, 2024, 2025]


sales = [150, 210, 180, 320, 410]

[Link](years, sales, marker='o', color='green', linestyle='--')


[Link]('Company Annual Sales Growth')
[Link]('Year')
[Link]('Sales (in Lakhs)')
[Link](True)
[Link]()
Use code with caution.
Program 9: Bar Chart Customization
 Aim: Plot categorical comparison datasets.
 Source Code:
python
import [Link] as plt

subjects = ['English', 'Maths', 'Science', 'Social', 'AI']


marks = [85, 92, 78, 88, 95]

[Link](subjects, marks, color=['red', 'blue', 'orange', 'purple',


'green'])
[Link]('Student Examination Marks Distribution')
[Link]('Subjects Offered')
[Link]('Marks Obtained')
[Link](0, 100)
[Link]()
Use code with caution.

SECTION 3: COMPUTER VISION (OPENCV)


Program 10: Reading and Displaying an Image

 Aim: Use OpenCV tools to render graphics dynamically.


 Source Code:
python
import cv2

# Note: Keep a sample image named '[Link]' in the same folder


image = [Link]('[Link]')

if image is None:
print("Error: Could not open or find the image.")
else:
[Link]('Display Window', image)
[Link](0)
[Link]()
Use code with caution.
Program 11: Image Grayscale Transformations
 Aim: Convert standard three-channel color representations into flat monochrome
tones.
 Source Code:
python
import cv2

image = [Link]('[Link]')
gray_image = [Link](image, cv2.COLOR_BGR2GRAY)

[Link]('Original Color Image', image)


[Link]('Processed Monochrome Image', gray_image)
[Link](0)
[Link]()
Use code with caution.
Program 12: Scaling and Image Resizing
 Aim: Change spatial image dimensions programmatically.
 Source Code:
python
import cv2

image = [Link]('[Link]')

# Resize image to dimensions (width=300, height=200)


resized_image = [Link](image, (300, 200))

[Link]('Resized Window Output', resized_image)


[Link](0)
[Link]()
Use code with caution.
SECTION 4: NATURAL LANGUAGE PROCESSING & AI
PROJECTS

Program 13: String Tokenization

 Aim: Divide paragraph text down into word units.


 Source Code:
python
sentence = "Artificial Intelligence is shaping the future of
education."
words = [Link]()

print("Original Sentence:", sentence)


print("Tokenized Words List:")
print(words)
Use code with caution.
Program 14: Filtering Stop Words
 Aim: Clean simple linguistic noise items out of sentences.
 Source Code:
python
stop_words = ["is", "the", "a", "an", "of", "and", "in"]
text = "Artificial Intelligence is a subset of computer science and
technology"

filtered_words = [word for word in [Link]() if [Link]() not in


stop_words]
print("Cleaned Text Output:", " ".join(filtered_words))
Use code with caution.
Practical 15: Teachable Machine Model Framework
 Aim: Implement an Image/Audio Classifier model using Google's cloud-based
training portal.
 Workflow Writeup:
1. Data Acquisition: Accessed Google Teachable Machine portal. Created two visual
distinction label classes: Class 1: Wearing Mask and Class 2: Not Wearing
Mask.
2. Model Training: Captured 100 sample images per class category utilizing standard
webcams. Set hyperparameters to 50 Epochs.
3. Evaluation and Output: Validated accuracy response via live input video feed.
Exported final model structural weights as Keras code configurations.

You might also like