Shubham Jha Python Practical
Shubham Jha Python Practical
Shubham Jha Python Practical
Practical File
Session [2022-23]
List1 = []
Num = int (input ('Enter Number of elements in the List:'))
for i in range (1, Num+1):
e=int (input ('Enter the elements:'))
List1.append(e)
print ('The largest element is:', max(List1))
OUTPUT :
Program-5
#Linear Search
def linear_Search(L,x):
for i in range(len(L)):
if (L[i] == x):
return i
return -1
L = []
for k in range(0,10):
n=int(input('Enter the elements to put in list :'))
L.append(n)
x=int(input('Enter the element to search:'))
result=linear_Search(L,x)
if(result==-1):
print('Element is not present in the array')
else:
print('Element is present at index :',result)
OUTPUT :
Program - 6
#Binary search
list1 = [1, 2, 3, 4, 5, 6, 7]
n=5
result = binary_search(list1, n)
if result != -1:
print("Element is present at index", str(result))
else:
print("Element is not present in list")
OUTPUT :
Program - 7
#Selection Sort)
def selectionSort(array, size):
for ind in range(size):
min_index = ind
for j in range(ind + 1, size):
# select the minimum element in every iteration
if array[j] < array[min_index]:
min_index = j
# swapping the elements to sort the array
(array[ind], array[min_index]) = (array[min_index],
array[ind])
arr = [-58, 4, 0, 14, -4, 69, -66, -6969, 3495, 584, 34, -234]
size = len(arr)
selectionSort(arr, size)
print('The array after sorting in Ascending Order by selection
sort is:')
print(arr
OUTPUT :
Program - 8
#Insertion Sort
def isort(L):
for i in range (0, len(L)):
temp=L[i]
j=i-1
while (j>=0 and temp<L[j]):
L[j+1]=L[j]
j=1
L[j+1]=temp
L=[]
m=int(input('Enter Size of List: '))
for k in range(0,m):
n=int(input('Enter Item Of List:
'))
L.append(n)
isort(L)
print('The insertion sorted list:',L)
OUTPUT :
Program - 9
#Merge sort
if c == 2:
print(i)
else:
k=k-1
i=i+1
OUTPUT :
PROGRAM-11:
#Multiplication of matrices
#3x3 matrix
X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[2,3,4,1],
[34,1,45,1],
[4,5,2,89]]
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
OUTPUT :
Program - 12
import sys
print(type(sys.argv))
print('The command line arguments are:')
for i in sys.argv:
print (i)
OUTPUT: