0% found this document useful (0 votes)
18 views2 pages

Python Programming Examples

Dhdhdhdhs

Uploaded by

tarungu2010
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)
18 views2 pages

Python Programming Examples

Dhdhdhdhs

Uploaded by

tarungu2010
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

Program 1: Add Elements of Two Lists

Aim: To write a Python program that adds the corresponding elements of two lists.
Program:
list1 = [1, 2, 3, 4, 5]
list2 = [10, 20, 30, 40, 50]
sum_list = []

for i in range(len(list1)):
sum_list.append(list1[i] + list2[i])

print("Sum of corresponding elements:", sum_list)

Program 2: Calculate Mean, Median and Mode using NumPy


Aim: To calculate the mean, median and mode of a dataset using NumPy and SciPy.
Program:
import numpy as np
from scipy import stats

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

mean_value = [Link](data)
median_value = [Link](data)
mode_value = [Link](data)

print("Mean:", mean_value)
print("Median:", median_value)
print("Mode:", mode_value.mode[0])

Program 3: Display a Line Chart


Aim: To plot a line chart from (2,5) to (9,10).
Program:
import [Link] as plt

x = [2, 3, 5, 7, 9]
y = [5, 7, 6, 8, 10]

[Link](x, y, marker='o', linestyle='-', color='b')


[Link]("x-axis")
[Link]("y-axis")
[Link]("Line Chart")
[Link]()

Program 4: Display a Scatter Chart


Aim: To create a scatter plot using Matplotlib.
Program:
import [Link] as plt

points = [(2,5), (9,10), (8,3), (5,7), (6,10)]


x, y = zip(*points)

[Link](x, y, color='r', marker='o')


[Link]("x-axis")
[Link]("y-axis")
[Link]("Scatter Chart")
[Link]()
Program 5: Read a CSV File and Display 10 Rows
Aim: To read a CSV file and display the first 10 rows using Pandas.
Program:
import pandas as pd

df = pd.read_csv("[Link]")
print([Link](10))

Program 6: Read a CSV File and Display Its Information


Aim: To read a CSV file and display its structure and details using Pandas.
Program:
import pandas as pd

df = pd.read_csv("[Link]")
print([Link]())

Program 7: Read an Image and Display It


Aim: To read and display an image using OpenCV and Matplotlib.
Program:
import cv2
import [Link] as plt

image = [Link]("[Link]")
image = [Link](image, cv2.COLOR_BGR2RGB)

[Link](image)
[Link]("off")
[Link]("Image Display")
[Link]()

Program 8: Read an Image and Identify Its Shape


Aim: To read an image and determine its height, width, and number of channels.
Program:
import cv2

image = [Link]("[Link]")
(height, width, channels) = [Link]

print("Image Height:", height)


print("Image Width:", width)
print("Number of Channels:", channels)

You might also like