0% found this document useful (0 votes)
26 views17 pages

AI Finalized

The document provides examples of Python programs for basic concepts like printing strings, making a simple calculator, solving quadratic equations, working with lists and their operations, data visualization using matplotlib, introduction to computer vision using OpenCV library, and common image manipulation tasks like resizing, extracting region of interest, and rotating images. Each example provides the aim, source code, output and result of executing the code. The programs cover fundamental Python programming concepts as well as applications in data science and computer vision.

Uploaded by

FroFee F
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)
26 views17 pages

AI Finalized

The document provides examples of Python programs for basic concepts like printing strings, making a simple calculator, solving quadratic equations, working with lists and their operations, data visualization using matplotlib, introduction to computer vision using OpenCV library, and common image manipulation tasks like resizing, extracting region of interest, and rotating images. Each example provides the aim, source code, output and result of executing the code. The programs cover fundamental Python programming concepts as well as applications in data science and computer vision.

Uploaded by

FroFee F
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/ 17

PRACTICAL PROGRAMS

PROGRAM NO-1

Python Basics-1
AIM- Write a Python program to print the following string in a specific format.

SOURCE CODE-
print("Twinkle, twinkle, little star, \n\tHow I wonder what you are! \n\t\tUp
above the world so high, \n\t\tLike a diamond in the sky. \nTwinkle, twinkle,
little star, \n\tHow I wonder what you are!")

OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

174
PROGRAM NO-2
Python Basics-2
AIM- Write a Python program to print 5 lines about yourself using print() function.
SOURCE CODE-

OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

175
PROGRAM NO-3
Python Basics-3

AIM- Write a program to make a simple calculator.


SOURCE CODE-

176
OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

177
PROGRAM NO-4
Python Basics-4

AIM- Write a python program which can solve a quadratic equation.


Formula: Let ax2 + bx + c = 0 is a quadratic equation where a, b and c are real

SOURCE CODE-

178
OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

179
PROGRAM NO-5
Python Basics-5
AIM- A tours and travels company charges their customer as per following criteria according
to customer category.
Category Charges

A 18

B 15

C 12

D 10

Others 20

SOURCE CODE-

OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

180
PROGRAM NO-6
LISTS AND ITS OPERATIONS
AIM- Write a Python program:-
1. To declare a list as num = [10, 30, 40, 20, 50] and print it.
2. To sort the list num in Ascending and the Descending order in Python.
3. To create a list as List1 = ['Hello', 10, 'world', 20] and iterate in reverse order.
4. To remove an element of List1 using List1.pop() .
5. To add an element to a List1 using List1.append().

SOURCE CODE-

# 1. List of integers num


num = [10, 30, 40, 20, 50]
print ("The num list :", num)

# 2. Sort the list num in Ascending order


num.sort()
print ("the list num in Ascending order: ", num)

#Sort the list num in Descending order


num.sort(reverse=True)
print ("The list num in decending order: ", num)

#3. Create list List1 and iterate


List1 = ['Hello', 10, 'world', 20]
print("The List1 :-", List1)
# iterate the list
List1 = List1[::-1]

# Print the list


print ("List1 in reverse order: ", List1)

#4. Removing elements


List1.pop() ;
# Printing list after removing
print("list elements after removing from List1: ", List1)

#5. adding elements to List1


List1.append(50)
List1.append("Chennai")
# Printing list after adding
print("list elements after adding to List1: ", List1)
181
OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

182
PROGRAM NO-7
DATA SCIENCE
Data Visualization Tools

AIM- Write a short note about five essential plots that can help in data visualization and write a
Python program to show each.

Introduction: Data visualization is the process of turning your data into graphical
representations that communicate logical relationships and lead to more informed
decision-making.In short, data visualization is the representation of data in a graphical or pictorial
format.
There are five essential plots that have we need to know well for basic data visualization.
Line Plot
Bar Chart
Histogram Plot
Scatter Plot
Pie Chart
1. Line Plot:
A line plot is used to show observations gathered at regular intervals.
-axis shows the regular interval, such as time.
- axis shows the observations.
-
axis data for the regular interval, and Y axis for the observations.
# code to create a line plot
pyplot.plot(x, y)
2. Bar Plot:
A bar chart presents relative quantities for multiple categories.
The x-axis shows the categories that are spaced evenly.
The Y- axis shows the quantity for each category and is drawn as a bar from the baseline to
the required level on the Y-axis.
A bar chart can be built by the calling the bar() function and passing the category names for
the X-axis and the quantities for the Y axis.
3. Histogram Plot
Histogram plots are used for summarizing the distribution of a data sample.
The x-axis shows distinct bins or intervals for the observation.
The Y- axis shows the frequency or tally of the number of observations
in the dataset that has assigned to each bin.
A Histogram plot can be designed by the calling the hist() function and
passing a list or array that shows the data sample.
# code to create a histogram plot
pyplot.hist(x, y)
4. Scatter Plot:
A scatter plot can be designed by the calling the scatter() function and passing a list or
array that shows the data sample.

183
# code to create a scatter plot
pyplot. Scatter(x, y)
5. Pie Chart
A Pie Chart is a circular statistical plot that can display only one series of data.
The area of the chart is the total percentage of the given data. The area of slices of
the pie represents the percentage of the parts of the data
# code to create a pie plot
pyplot.pie(values, labels = Names)

SOURCE CODE-

184
185
OUTPUT-

186
RESULT- The source code is executed successfully and the output was verified.

187
PROGRAM NO-8
INTRODUCTION TO COMPUTER VISION
AIM- Write a Python program
a. To read and display an image using OpenCV in Google Colab.
b. To dsiplay the height and width of an input image.
c. To covert BGR format of OpenCV to RGB format.

Introduction:
Computer Vision Computer vision is a field/domain of artificial intelligence (AI) that enables
computers and systems to derive meaningful information from digital images, videos and other
visual inputs and take actions or make recommendations based on that information.
OpenCV-Python is a library of Python bindings designed to solve computer vision problems.
Python is a general purpose programming language started by Guido van Rossum that became
very popular very quickly, mainly because of its simplicity and code readability. It enables the
programmer to express ideas in fewer lines of code without reducing readability. OpenCV was
started at Intel in 1999 by Gary Bradsky, and the first release came out in 2000. Vadim Pisarevsky
joined Gary Bradsky to manage Intel's Russian software OpenCV team. In 2005, OpenCV was
used on Stanley, the vehicle that won the 2005 DARPA Grand Challenge.

SOURCE CODE-
# Importing the OpenCV library
import cv2
# Importing the matplotlib library
import matplotlib.pyplot as plt

# Reading the image using imread() function


image = cv2.imread('/road.jpg')
# Displaying the image using imshow() function
plt.imshow(image)

# Extracting the height and width of an image


h, w = image.shape[:2]
# Displaying the height and width
print("Height = {}, Width = {}".format(h, w))

# Converting the image to RGB format using cvtColor() function


imgrgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(imgrgb),plt.title("RGB FROMAT of given Image")
# Extracting the height and width of an image
h, w = imgrgb.shape[:2]
# Displaying the height and width
print("Height = {}, Width = {}".format(h, w))

188
OUTPUT-

RESULT- The source code is executed successfully and the output was verified.

189
PROGRAM NO-9
COMMON IMAGE MANIPULATION USING OpenCV

AIM- Write a Python program


a. To resize the image using resize().
b. To dsiplay the region of interest of an image.
c. To rotate an image.

SOURCE CODE-
# Importing the OpenCV library
import cv2
# Importing the matplotlib library
import matplotlib.pyplot as plt

# Reading the image using imread() function


image = cv2.imread('/road.jpg')
# Displaying the image using imshow() function
plt.imshow(image)

# Extracting the height and width of an image


h, w = image.shape[:2]
# Displaying the height and width
print("Height = {}, Width = {}".format(h, w))

# resize() function takes 2 parameters,


# the image and the dimensions
resize = cv2.resize(image, (800, 800))
plt.imshow(resize)

# We will calculate the region of interest


# by slicing the pixels of the image
roi = image[100 : 500, 200 : 700]
plt.imshow(roi),plt.title("REGION OF INTEREST IMAGE")

# Calculating the center of the image


center = (w // 2, h // 2)

# Generating a rotation matrix


matrix = cv2.getRotationMatrix2D(center, -45, 1.0)

# Performing the affine transformation


rotated = cv2.warpAffine(image, matrix, (w, h))
plt.imshow(rotated),plt.title("ROTATED IMAGE")

190

You might also like