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

Python List and Array Operations

The document outlines a Python programming experiment focused on lists, detailing three tasks: calculating mean, median, and mode from a list of numbers; converting a list and tuple into arrays using NumPy; and finding common values between two arrays. Each task includes sample code and expected outputs. The experiment is part of a laboratory course at VNRVJIET.

Uploaded by

Mailu
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)
4 views2 pages

Python List and Array Operations

The document outlines a Python programming experiment focused on lists, detailing three tasks: calculating mean, median, and mode from a list of numbers; converting a list and tuple into arrays using NumPy; and finding common values between two arrays. Each task includes sample code and expected outputs. The experiment is part of a laboratory course at VNRVJIET.

Uploaded by

Mailu
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

Sheet No: ……………

VNRVJIET
Name of the Experiment: Lists
Name of the Laboratory:
Python Programming and Practice Experiment No.: 4 Date:

a) Write a program to find mean, median, mode for the given set of numbers in a list.
Code:
list = input("Enter set numbers: ").split()
list = [int(x) for x in list]
n = len(list)
sum = 0
for i in range(n):
sum += list[i]
mean = sum / n
print("Mean:",mean)
[Link]()
median=0
if n % 2 == 0:
median = (list[n//2 - 1] + list[n//2]) / 2
else:
median = list[n//2]
print("Median:",median)
mode = 3*median - 2*mean
print("Mode:",mode)
Output:

b) Write a program to convert a list and tuple into arrays.


Code:
import numpy as np

list1 = [1, 2, 3, 4, 5]
tuple2 = (1, 2, 3, 4, 5)
li_to_ar = [Link](list1)
tup_to_ar = [Link](tuple2)
print("List to array is: ", li_to_ar)
print("Tuple to array is: ", tup_to_ar)
Sheet No: ……………
VNRVJIET
Name of the Experiment: Lists
Name of the Laboratory:
Python Programming and Practice Experiment No.: 4 Date:

Output:

c) Write a program to find common values between two arrays.


Code:
array1 = [3,6,9,12,15]
array2 = [1,3,10,15,39]
common_values = list(set(array1) & set(array2))

print("Array 1:", array1)


print("Array 2:", array2)
print("Common values:", common_values)
Output:

You might also like