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: