Practicle 1
def accept_set(A,Str):
n = int(input("Enterthe total no.of studentwhoplay%s: "%Str))
for i in range(n) :
x = input("Enterthe name of student%dwhoplay%s: "%((i+1),Str))
A.append(x)
print("Setaccepted successfully");
def display_set(A,Str):
n = len(A)
if(n== 0) :
print("nGroupof Studentswhoplay%s= { }"%Str)
else :
print("nGroupof Studentswhoplay%s= {"%Str,end='')
for i in range(n-1) :
print("%s,"%A[i],end='')
print("%s}"%A[n-1]);
def search_set(A,X) :
n = len(A)
for i inrange(n):
if(A[i] ==X) :
return(1)
return(0)
def find_intersection_set(A,B,C):
for i in range(len(A)):
flag= search_set(B,A[i]);
if(flag==1) :
C.append(A[i])
def find_difference_set(A,B,C):
for i inrange(len(A)):
flag= search_set(B,A[i]);
if(flag==0) :
C.append(A[i])
def find_union_set(A,B,C):
for i in range(len(A)):
C.append(A[i])
for i in range(len(B)):
flag= search_set(A,B[i]);
if(flag==0) :
C.append(B[i])
Group_A = []
Group_B = []
Group_C = []
while True :
accept_set(Group_A,"Cricket")
accept_set(Group_B,"Badminton")
accept_set(Group_C,"Football")
display_set(Group_A,"Cricket")
display_set(Group_B,"Badminton")
display_set(Group_C,"Football")
break
def main() :
print("______________MENU___________")
print("1 : Listof studentswhoplaybothcricketandbadminton")
print("2 : Listof studentswhoplayeithercricketorbadmintonbutnotboth")
print("3 : Numberof studentswhoplayneithercricketnorbadminton")
print("4 : Numberof studentswhoplaycricketandfootball butnotbadminton")
print("5 : Exit")
ch = int(input("Enteryourchoice :"))
Group_R = []
if (ch==1):
display_set(Group_A,"Cricket")
display_set(Group_B,"Badminton")
find_intersection_set(Group_A,Group_B,Group_R)
display_set(Group_R,"bothCricketandBadminton")
print()
main()
elif (ch==2):
display_set(Group_A,"Cricket")
display_set(Group_B,"Badminton")
R1 = []
find_union_set(Group_A,Group_B,R1)
R2 = []
find_intersection_set(Group_A,Group_B,R2)
find_difference_set(R1,R2,Group_R)
display_set(Group_R,"eithercricketorbadmintonbutnotboth")
print()
main()
elif (ch==3):
display_set(Group_A,"Cricket")
display_set(Group_B,"Badminton")
display_set(Group_C,"Football")
R1 = []
find_union_set(Group_A,Group_B,R1)
find_difference_set(Group_C,R1,Group_R)
display_set(Group_R,"neithercricketnorbadminton")
print("Numberof studentswhoplayneithercricketnorbadminton=%s"%len(Group_R))
print()
main()
elif (ch==4):
display_set(Group_A,"Cricket")
display_set(Group_C,"Football")
display_set(Group_B,"Badminton")
R1 = []
find_intersection_set(Group_A,Group_C,R1)
find_difference_set(R1,Group_B,Group_R)
display_set(Group_R,"cricketandfootball butnotbadminton")
print("Numberof studentswhoplaycricketandfootballbutnotbadminton=%s"%len(Group_R))
print()
main()
elif (ch==5):
exit
else :
print ("Wrongchoice entered!!Tryagain")
main()
practicle 2
# The average_score score of class
def average_score(l):
sum = 0
cnt = 0
for i inrange(len(l)):
if l[i] !=-1:
sum+= l[i]
cnt += 1
avg = sum/ cnt
print("Total Marksare : ", sum)
print("average_scoreMarksare : {:.2f}".format(avg))
# Highestscore inthe class
def highest_score(l):
Max = l[0]
for i inrange(len(l)):
if l[i] >Max:
Max = l[i]
return(Max)
# Lowestscore inthe class
def lowest_score(l):
# Assignfirstelementinthe arraywhichcorrespondstomarksof firstpresentstudent
# Thisfor loopensuresthe above condition
for i inrange(len(l)):
if l[i] !=-1:
Min = l[i]
break
for j inrange(i + 1, len(l)):
if l[j] !=-1 andl[j] < Min:
Min = l[j]
return(Min)
# Countof studentswhowere absentforthe test
def absent_student(l):
cnt = 0
for i inrange(len(l)):
if l[i] == -1:
cnt += 1
return(cnt)
# Displaymarkwithhighestfrequency
# refeence link:https://www.youtube.com/watch?v=QrIXGqvvpk4&t=422s
def highest_frequancy(l):
i = 0
Max = 0
print("Marks ---->frequencycount")
for ele inl:
if l.index(ele)==i:
print(ele,"---->",l.count(ele))
if l.count(ele) >Max:
Max = l.count(ele)
mark = ele
i += 1
return(mark,Max)
# Inputthe numberof studentsandtheircorrespondingmarksinFDS
student_marks= []
noStudents=int(input("Entertotal numberof students:"))
for i in range(noStudents):
marks = int(input("Entermarksof Student"+ str(i + 1) + " : "))
student_marks.append(marks)
def main():
print("tt__________MENU_________")
print("1.The average_score score of class ")
print("2.Highestscore andlowestscore of class ")
print("3.Countof studentswhowere absentforthe test")
print("4.Displaymarkwithhighestfrequency")
print("5.Exit")
choice = int(input("Enteryourchoice :"))
if choice == 1:
average_score(student_marks)
print()
main()
elif choice == 2:
print("Highestscore inthe classis: ", highest_score(student_marks))
print("Lowestscore inthe classis: ", lowest_score(student_marks))
print()
main()
elif choice == 3:
print("Countof studentswhowere absentforthe testis: ", absent_student(student_marks))
print()
main()
elif choice == 4:
mark,count = highest_frequancy(student_marks)
print("Highestfrequencyof marks{0} is{1} ".format(mark,count))
print()
main()
elif choice == 5:
exit
else:
print("Wrongchoice")
print()
main()
practicle 3
print("basicmatrix operationusingpython")
m1=[]
m=[]
m2=[]
res=[[0,0,0,0,0],[0,0,0,0,0], [0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
print("enterthe numberof rowsandcolums")
row1=int(input("enternoof rowsinfirstmatrix:"))
col1=int(input("enternoof columninfirstmatrix:"))
row2=int(input("enternoof rowsinsecondmatrix:"))
col2=int(input("enternoof rows insecondmatrix:"))
def main():
print("1.additionof twomatrix")
print("2.subtractionof twomatrix ")
print("3.multiplicationof twomatrix")
print("4.transpose of firstmatrix")
print("5.transpose of secondmatrix")
print("6.exit")
choice =int(input("enteryourchoice:"))
if choice==1:
print("additionof twomatrix")
if ((row1==row2)and(col1==col2)):
matrix_addition(m1,m2,row1,col1)
show_matrix(res,row1,col1)
else:
print("additionisnotpossible")
print()
main()
elif choice==2:
print("subtractionof twomatrix")
if ((row1==row2)and(col1==col2)):
matrix_subtraction(m1,m2,row1,col1)
show_matrix(res,row1,col1)
else:
print("subtractionisnotpossible")
print()
main()
elif choice==3:
print("multiplicationof matrix")
if (col1==row2):
matrix_multiplication(m1,m2,row2,col1)
show_matrix(res,row2,col1)
else:
print("multiplicationisnot possible")
print()
main()
elif choice==4:
print("afterapplyingtranspose matrix elemntare:")
matrix_transpose(m1,row1,col1)
show_matrix(res,row1,col1)
print()
main()
elif choice==5:
print("afterapplyingtranspose matrix elemntare:")
matrix_transpose(m1,row1,col1)
show_matrix(res,row2,col2)
print()
main()
elif choice==6:
exit
else:
print("entervalidchoice")
def accept_matrix(m,row,col):
for i inrange (row):
c=[]
forj inrange(col):
no=int(input("enterthe value of matrix["+str(i) +"] [" + str(j) + "]::"))
c.append(no)
print("-----------------")
m.append(c)
print("enterthe value of forfirstmatrix")
accept_matrix(m1,row1,col1)
print("enterthe value forsecondmatrix")
accept_matrix(m2,row2,col2)
def show_matrix(m,row,col):
for i inrange(row):
forj inrange(col):
print(m[i][j],end="")
print()
# show_matrix matrix
print("the firstmatrix is:")
show_matrix(m1,row1,col1)
print("the secondmatrix :")
show_matrix(m2,row2,col2)
def matrix_addition(m1,m2,row,col):
for i inrange(row):
forj inrange(col):
res[i][j]=m1[i][j]+m2[i][j]
def matrix_subtraction(m1,m2,row,col):
for i inrange(row):
forj inrange(col):
res[i][j]=m1[i][j] - m2[i][j]
def matrix_multiplication(m1,m2,row,col):
for i inrange (row):
forj inrange(col):
fork in range(col):
res[i][j]=res[i][j]+m1[i][k]*m2[k][j]
def matrix_transpose(m,row,col):
for i inrange (row):
forj inrange(col):
res[i][j]=m[j][i]
main()
practicle 4
#-----------------------------------------------
"""
Write a pythonprogram to store firstyearpercentage of studentsinarray.
Write functionforsortingarray of floatingpointnumbersinascendingorderusing
a) SelectionSort
b) Bubble sortand displaytopfive scores.
"""
def bubbleSort(arr):
n = len(arr)
for i inrange(n-1):
forj inrange(0,n-i-1):
if arr[j] > arr[j+1] :
arr[j],arr[j+1] = arr[j+1], arr[j]
def selectionSort(arr):
fori inrange(len(arr)):
min_idx =i
forj inrange(i+1,len(arr)):
if arr[min_idx] >arr[j]:
min_idx = j
arr[i],arr[min_idx] =arr[min_idx],arr[i]
def top_five(arr):
print("Topfive score are : ")
cnt = len(arr)
if cnt < 5:
start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element
else:
start,stop = cnt - 1, cnt - 6
for i inrange(start,stop, -1):
print("t{0:.2f}".format(arr[i]),end="")
arr=[]
Num=int(input("Enterthe numberof students:"))
for i in range (Num):
per=float(input("Enterthe marksof student"+ str(i+1) + " : "))
arr.append(per)
def main():
print("1.selectionsort")
print("2.bubble sort")
print("3.displaytopfive marks")
print("4.exit")
choice=int(input("enterchoice forsort:"))
if choice==1:
selectionSort(arr)
print("Sortedarray")
m=[]
fori inrange(len(arr)):
m.append(arr)
print(m)
break
print()
main()
elif choice==2:
bubbleSort(arr)
print("Sortedarrayis:")
n=[]
fori inrange(len(arr)):
n.append(arr)
print(n)
break
main()
elif choice==3:
top_five(arr)
elif choice==4:
exit
else:
print("entervalidinput")
print(arr)
main()
practicle 5
"""
Write a pythonprogram to store firstyearpercentage of studentsinarray.
Write functionforsortingarray of floatingpointnumbersinascendingorderusing
a) shell sort
b) Insertionsortand displaytopfive scores.
"""
def shellSort(arr):
n = len(arr)
gap = n // 2
# Do a gappedinsertion_sortforthisgapsize.
# The firstgap elementsa[0..gap-1] are alreadyingapped
# orderkeepaddingone more elementuntil the entire array
# isgap sorted
while gap> 0:
fori inrange(gap,n):
# add arr[i] to the elementsthathave beengapsorted
# save arr[i] in tempand make a hole at positioni
temp= arr[i]
# shiftearliergap-sortedelementsupuntil the correct
# locationforarr[i] is found
j = i
while j >= gap and arr[j - gap] > temp:
arr[j] = arr[j - gap]
j -= gap
# puttemp(the original arr[i]) initscorrectlocation
arr[j] = temp
gap //=2
returnarr
def insertion_sort(arr):
for i inrange(1,len(arr)):
key= arr[i]
# Move elementsof a[0..i-1],thatare
# greaterthan key,toone positionahead
# of theircurrentposition
j = i - 1
while j >= 0 andkey< arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
returnarr
def top_five(arr):
print("Topfive score are : ")
cnt = len(arr)
if cnt < 5:
start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element
else:
start,stop = cnt - 1, cnt - 6
for i inrange(start,stop, -1):
print("t{0:.2f}".format(arr[i]),end="")
arr=[]
Num=int(input("Enterthe numberof students:"))
for i in range (Num):
per=float(input("Enterthe marksof student"+ str(i+1) + " : "))
arr.append(per)
def main():
print("1.shell sort")
print("2.insertion sort")
print("3.displaytopfive marks")
print("4.exit")
choice=int(input("enterchoice forsort:"))
if choice==1:
insertion_sort(arr)
print("Sortedarray")
m=[]
fori inrange(len(arr)):
m.append(arr)
print(m)
break
print()
main()
elif choice==2:
shellSort(arr)
print("Sortedarrayis:")
n=[]
fori inrange(len(arr)):
n.append(arr)
print(n)
break
main()
elif choice==3:
top_five(arr)
elif choice==4:
exit
else:
print("entervalidinput")
print(arr)
main()
practicle 6
#-----------------------------------------------
"""
Write a pythonprogram to store firstyearpercentage of studentsinarray.
Write functionforsortingarray of floatingpointnumbersinascendingorderusing
a) quick_sortsortdisplaytopfive scores.
"""
print("tt______________PROGRAM_____________")
print()
def Partition(arr,low,high):
pivot= arr[low]
i=low+1
j=high
flag= False
while(notflag):
while(i<=j andarr[i]<=pivot):
i = i + 1
while(i<=j andarr[j]>=pivot):
j = j - 1
if(j<i):
flag= True
else:
temp= arr[i]
arr[i] = arr[j]
arr[j] = temp
temp= arr[low]
arr[low] = arr[j]
arr[j] = temp
returnj
def quick_sort(arr,low,high):
if(low<high):
m=Partition(arr,low,high)
quick_sort(arr,low,m-1)
quick_sort(arr,m+1,high)
def top_five(arr):
print("Topfive score are : ")
cnt = len(arr)
if cnt < 5:
start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element
else:
start,stop = cnt - 1, cnt - 6
for i inrange(start,stop, -1):
print("t{0:.2f}".format(arr[i]),end="")
arr=[]
Num=int(input("Enterthe numberof students:"))
for i in range (Num):
per=float(input("Enterthe marksof student"+ str(i+1) + " : "))
arr.append(per)
def main():
print("__________MENU__________")
print("1.quick_sortsort")
print("2.displaytopfive marks")
print("3.exit")
choice=int(input("enterchoice forsort:"))
if choice==1:
quick_sort(arr,0,Num-1)
print("Sortedarray")
print(arr)
print()
main()
elif choice==2:
top_five(arr)
print()
main()
elif choice==3:
exit
else:
print("entervalidinput")
print(arr)
main()

More Related Content

PDF
fds Practicle 1to 6 program.pdf
PDF
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
DOCX
Python real time tutorial
DOC
Basic c programs updated on 31.8.2020
DOCX
cs class 12 project computer science .docx
PDF
VTU Data Structures Lab Manual
PDF
programs on arrays.pdf
PPTX
L25-L26-Parameter passing techniques.pptx
fds Practicle 1to 6 program.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Python real time tutorial
Basic c programs updated on 31.8.2020
cs class 12 project computer science .docx
VTU Data Structures Lab Manual
programs on arrays.pdf
L25-L26-Parameter passing techniques.pptx

Similar to Practicle 1.docx (20)

DOCX
Recursion in C
DOCX
ECE-PYTHON.docx
PPT
Struct examples
PPT
array.ppt
PPTX
Python Statistics.pptx
DOCX
Basic python laboratoty_ PSPP Manual .docx
PDF
Xi CBSE Computer Science lab programs
PPTX
one dimentional array on programming with C
PDF
Quantum simulation Mathematics and Python examples
PDF
Baby Steps to Machine Learning at DevFest Lagos 2019
DOCX
Ml all programs
PDF
Algorithm Design and Analysis - Practical File
PDF
data structure and algorithm.pdf
DOCX
Aastha Shah.docx
PPT
All important c programby makhan kumbhkar
PDF
python practicals-solution-2019-20-class-xii.pdf
PDF
Kotlin for Android Developers - 2
PDF
Assignment on Numerical Method C Code
DOCX
Solutionsfor co2 C Programs for data structures
PDF
xii cs practicals
Recursion in C
ECE-PYTHON.docx
Struct examples
array.ppt
Python Statistics.pptx
Basic python laboratoty_ PSPP Manual .docx
Xi CBSE Computer Science lab programs
one dimentional array on programming with C
Quantum simulation Mathematics and Python examples
Baby Steps to Machine Learning at DevFest Lagos 2019
Ml all programs
Algorithm Design and Analysis - Practical File
data structure and algorithm.pdf
Aastha Shah.docx
All important c programby makhan kumbhkar
python practicals-solution-2019-20-class-xii.pdf
Kotlin for Android Developers - 2
Assignment on Numerical Method C Code
Solutionsfor co2 C Programs for data structures
xii cs practicals
Ad

More from GaneshPawar819187 (6)

PDF
DSA Presentetion Huffman tree.pdf
PDF
dsa pract 2.pdf
DOCX
DOCX
fds u1.docx
DOCX
Dsa pract1.docx
DOCX
dsa pract 2.docx
DSA Presentetion Huffman tree.pdf
dsa pract 2.pdf
fds u1.docx
Dsa pract1.docx
dsa pract 2.docx
Ad

Recently uploaded (20)

PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
Trump Administration's workforce development strategy
PDF
HVAC Specification 2024 according to central public works department
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Virtual and Augmented Reality in Current Scenario
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Computer Architecture Input Output Memory.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
A powerpoint presentation on the Revised K-10 Science Shaping Paper
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Empowerment Technology for Senior High School Guide
Introduction to pro and eukaryotes and differences.pptx
TNA_Presentation-1-Final(SAVE)) (1).pptx
Trump Administration's workforce development strategy
HVAC Specification 2024 according to central public works department
Chinmaya Tiranga quiz Grand Finale.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Virtual and Augmented Reality in Current Scenario
Unit 4 Computer Architecture Multicore Processor.pptx
My India Quiz Book_20210205121199924.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Computer Architecture Input Output Memory.pptx

Practicle 1.docx

  • 1. Practicle 1 def accept_set(A,Str): n = int(input("Enterthe total no.of studentwhoplay%s: "%Str)) for i in range(n) : x = input("Enterthe name of student%dwhoplay%s: "%((i+1),Str)) A.append(x) print("Setaccepted successfully"); def display_set(A,Str): n = len(A) if(n== 0) : print("nGroupof Studentswhoplay%s= { }"%Str) else : print("nGroupof Studentswhoplay%s= {"%Str,end='') for i in range(n-1) : print("%s,"%A[i],end='') print("%s}"%A[n-1]); def search_set(A,X) : n = len(A) for i inrange(n): if(A[i] ==X) : return(1) return(0) def find_intersection_set(A,B,C): for i in range(len(A)):
  • 2. flag= search_set(B,A[i]); if(flag==1) : C.append(A[i]) def find_difference_set(A,B,C): for i inrange(len(A)): flag= search_set(B,A[i]); if(flag==0) : C.append(A[i]) def find_union_set(A,B,C): for i in range(len(A)): C.append(A[i]) for i in range(len(B)): flag= search_set(A,B[i]); if(flag==0) : C.append(B[i]) Group_A = [] Group_B = [] Group_C = [] while True : accept_set(Group_A,"Cricket") accept_set(Group_B,"Badminton") accept_set(Group_C,"Football") display_set(Group_A,"Cricket") display_set(Group_B,"Badminton")
  • 3. display_set(Group_C,"Football") break def main() : print("______________MENU___________") print("1 : Listof studentswhoplaybothcricketandbadminton") print("2 : Listof studentswhoplayeithercricketorbadmintonbutnotboth") print("3 : Numberof studentswhoplayneithercricketnorbadminton") print("4 : Numberof studentswhoplaycricketandfootball butnotbadminton") print("5 : Exit") ch = int(input("Enteryourchoice :")) Group_R = [] if (ch==1): display_set(Group_A,"Cricket") display_set(Group_B,"Badminton") find_intersection_set(Group_A,Group_B,Group_R) display_set(Group_R,"bothCricketandBadminton") print() main() elif (ch==2): display_set(Group_A,"Cricket") display_set(Group_B,"Badminton") R1 = [] find_union_set(Group_A,Group_B,R1) R2 = [] find_intersection_set(Group_A,Group_B,R2) find_difference_set(R1,R2,Group_R)
  • 4. display_set(Group_R,"eithercricketorbadmintonbutnotboth") print() main() elif (ch==3): display_set(Group_A,"Cricket") display_set(Group_B,"Badminton") display_set(Group_C,"Football") R1 = [] find_union_set(Group_A,Group_B,R1) find_difference_set(Group_C,R1,Group_R) display_set(Group_R,"neithercricketnorbadminton") print("Numberof studentswhoplayneithercricketnorbadminton=%s"%len(Group_R)) print() main() elif (ch==4): display_set(Group_A,"Cricket") display_set(Group_C,"Football") display_set(Group_B,"Badminton") R1 = [] find_intersection_set(Group_A,Group_C,R1) find_difference_set(R1,Group_B,Group_R) display_set(Group_R,"cricketandfootball butnotbadminton") print("Numberof studentswhoplaycricketandfootballbutnotbadminton=%s"%len(Group_R)) print() main() elif (ch==5): exit else : print ("Wrongchoice entered!!Tryagain")
  • 5. main() practicle 2 # The average_score score of class def average_score(l): sum = 0 cnt = 0 for i inrange(len(l)): if l[i] !=-1: sum+= l[i] cnt += 1 avg = sum/ cnt print("Total Marksare : ", sum) print("average_scoreMarksare : {:.2f}".format(avg)) # Highestscore inthe class def highest_score(l): Max = l[0] for i inrange(len(l)): if l[i] >Max: Max = l[i] return(Max)
  • 6. # Lowestscore inthe class def lowest_score(l): # Assignfirstelementinthe arraywhichcorrespondstomarksof firstpresentstudent # Thisfor loopensuresthe above condition for i inrange(len(l)): if l[i] !=-1: Min = l[i] break for j inrange(i + 1, len(l)): if l[j] !=-1 andl[j] < Min: Min = l[j] return(Min) # Countof studentswhowere absentforthe test def absent_student(l): cnt = 0 for i inrange(len(l)): if l[i] == -1: cnt += 1 return(cnt)
  • 7. # Displaymarkwithhighestfrequency # refeence link:https://www.youtube.com/watch?v=QrIXGqvvpk4&t=422s def highest_frequancy(l): i = 0 Max = 0 print("Marks ---->frequencycount") for ele inl: if l.index(ele)==i: print(ele,"---->",l.count(ele)) if l.count(ele) >Max: Max = l.count(ele) mark = ele i += 1 return(mark,Max) # Inputthe numberof studentsandtheircorrespondingmarksinFDS student_marks= [] noStudents=int(input("Entertotal numberof students:")) for i in range(noStudents): marks = int(input("Entermarksof Student"+ str(i + 1) + " : ")) student_marks.append(marks) def main(): print("tt__________MENU_________") print("1.The average_score score of class ") print("2.Highestscore andlowestscore of class ")
  • 8. print("3.Countof studentswhowere absentforthe test") print("4.Displaymarkwithhighestfrequency") print("5.Exit") choice = int(input("Enteryourchoice :")) if choice == 1: average_score(student_marks) print() main() elif choice == 2: print("Highestscore inthe classis: ", highest_score(student_marks)) print("Lowestscore inthe classis: ", lowest_score(student_marks)) print() main() elif choice == 3: print("Countof studentswhowere absentforthe testis: ", absent_student(student_marks)) print() main() elif choice == 4: mark,count = highest_frequancy(student_marks) print("Highestfrequencyof marks{0} is{1} ".format(mark,count)) print() main() elif choice == 5: exit else: print("Wrongchoice")
  • 9. print() main() practicle 3 print("basicmatrix operationusingpython") m1=[] m=[] m2=[] res=[[0,0,0,0,0],[0,0,0,0,0], [0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] print("enterthe numberof rowsandcolums") row1=int(input("enternoof rowsinfirstmatrix:")) col1=int(input("enternoof columninfirstmatrix:")) row2=int(input("enternoof rowsinsecondmatrix:")) col2=int(input("enternoof rows insecondmatrix:")) def main(): print("1.additionof twomatrix") print("2.subtractionof twomatrix ") print("3.multiplicationof twomatrix") print("4.transpose of firstmatrix") print("5.transpose of secondmatrix") print("6.exit") choice =int(input("enteryourchoice:"))
  • 10. if choice==1: print("additionof twomatrix") if ((row1==row2)and(col1==col2)): matrix_addition(m1,m2,row1,col1) show_matrix(res,row1,col1) else: print("additionisnotpossible") print() main() elif choice==2: print("subtractionof twomatrix") if ((row1==row2)and(col1==col2)): matrix_subtraction(m1,m2,row1,col1) show_matrix(res,row1,col1) else: print("subtractionisnotpossible") print() main() elif choice==3: print("multiplicationof matrix") if (col1==row2): matrix_multiplication(m1,m2,row2,col1) show_matrix(res,row2,col1) else: print("multiplicationisnot possible") print() main() elif choice==4:
  • 11. print("afterapplyingtranspose matrix elemntare:") matrix_transpose(m1,row1,col1) show_matrix(res,row1,col1) print() main() elif choice==5: print("afterapplyingtranspose matrix elemntare:") matrix_transpose(m1,row1,col1) show_matrix(res,row2,col2) print() main() elif choice==6: exit else: print("entervalidchoice") def accept_matrix(m,row,col): for i inrange (row): c=[] forj inrange(col): no=int(input("enterthe value of matrix["+str(i) +"] [" + str(j) + "]::")) c.append(no) print("-----------------") m.append(c) print("enterthe value of forfirstmatrix")
  • 12. accept_matrix(m1,row1,col1) print("enterthe value forsecondmatrix") accept_matrix(m2,row2,col2) def show_matrix(m,row,col): for i inrange(row): forj inrange(col): print(m[i][j],end="") print() # show_matrix matrix print("the firstmatrix is:") show_matrix(m1,row1,col1) print("the secondmatrix :") show_matrix(m2,row2,col2) def matrix_addition(m1,m2,row,col): for i inrange(row): forj inrange(col): res[i][j]=m1[i][j]+m2[i][j] def matrix_subtraction(m1,m2,row,col): for i inrange(row): forj inrange(col): res[i][j]=m1[i][j] - m2[i][j] def matrix_multiplication(m1,m2,row,col): for i inrange (row): forj inrange(col):
  • 13. fork in range(col): res[i][j]=res[i][j]+m1[i][k]*m2[k][j] def matrix_transpose(m,row,col): for i inrange (row): forj inrange(col): res[i][j]=m[j][i] main() practicle 4 #----------------------------------------------- """ Write a pythonprogram to store firstyearpercentage of studentsinarray. Write functionforsortingarray of floatingpointnumbersinascendingorderusing a) SelectionSort b) Bubble sortand displaytopfive scores. """ def bubbleSort(arr): n = len(arr) for i inrange(n-1): forj inrange(0,n-i-1): if arr[j] > arr[j+1] : arr[j],arr[j+1] = arr[j+1], arr[j]
  • 14. def selectionSort(arr): fori inrange(len(arr)): min_idx =i forj inrange(i+1,len(arr)): if arr[min_idx] >arr[j]: min_idx = j arr[i],arr[min_idx] =arr[min_idx],arr[i] def top_five(arr): print("Topfive score are : ") cnt = len(arr) if cnt < 5: start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element else: start,stop = cnt - 1, cnt - 6 for i inrange(start,stop, -1): print("t{0:.2f}".format(arr[i]),end="") arr=[] Num=int(input("Enterthe numberof students:")) for i in range (Num): per=float(input("Enterthe marksof student"+ str(i+1) + " : ")) arr.append(per)
  • 15. def main(): print("1.selectionsort") print("2.bubble sort") print("3.displaytopfive marks") print("4.exit") choice=int(input("enterchoice forsort:")) if choice==1: selectionSort(arr) print("Sortedarray") m=[] fori inrange(len(arr)): m.append(arr) print(m) break print() main() elif choice==2: bubbleSort(arr) print("Sortedarrayis:") n=[] fori inrange(len(arr)): n.append(arr) print(n) break main() elif choice==3: top_five(arr)
  • 16. elif choice==4: exit else: print("entervalidinput") print(arr) main() practicle 5 """ Write a pythonprogram to store firstyearpercentage of studentsinarray. Write functionforsortingarray of floatingpointnumbersinascendingorderusing a) shell sort b) Insertionsortand displaytopfive scores. """ def shellSort(arr): n = len(arr) gap = n // 2 # Do a gappedinsertion_sortforthisgapsize. # The firstgap elementsa[0..gap-1] are alreadyingapped # orderkeepaddingone more elementuntil the entire array # isgap sorted while gap> 0: fori inrange(gap,n): # add arr[i] to the elementsthathave beengapsorted
  • 17. # save arr[i] in tempand make a hole at positioni temp= arr[i] # shiftearliergap-sortedelementsupuntil the correct # locationforarr[i] is found j = i while j >= gap and arr[j - gap] > temp: arr[j] = arr[j - gap] j -= gap # puttemp(the original arr[i]) initscorrectlocation arr[j] = temp gap //=2 returnarr def insertion_sort(arr): for i inrange(1,len(arr)): key= arr[i] # Move elementsof a[0..i-1],thatare # greaterthan key,toone positionahead # of theircurrentposition j = i - 1 while j >= 0 andkey< arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key returnarr
  • 18. def top_five(arr): print("Topfive score are : ") cnt = len(arr) if cnt < 5: start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element else: start,stop = cnt - 1, cnt - 6 for i inrange(start,stop, -1): print("t{0:.2f}".format(arr[i]),end="") arr=[] Num=int(input("Enterthe numberof students:")) for i in range (Num): per=float(input("Enterthe marksof student"+ str(i+1) + " : ")) arr.append(per) def main(): print("1.shell sort") print("2.insertion sort") print("3.displaytopfive marks") print("4.exit") choice=int(input("enterchoice forsort:")) if choice==1:
  • 19. insertion_sort(arr) print("Sortedarray") m=[] fori inrange(len(arr)): m.append(arr) print(m) break print() main() elif choice==2: shellSort(arr) print("Sortedarrayis:") n=[] fori inrange(len(arr)): n.append(arr) print(n) break main() elif choice==3: top_five(arr) elif choice==4: exit else: print("entervalidinput") print(arr) main()
  • 20. practicle 6 #----------------------------------------------- """ Write a pythonprogram to store firstyearpercentage of studentsinarray. Write functionforsortingarray of floatingpointnumbersinascendingorderusing a) quick_sortsortdisplaytopfive scores. """ print("tt______________PROGRAM_____________") print() def Partition(arr,low,high): pivot= arr[low] i=low+1 j=high flag= False while(notflag): while(i<=j andarr[i]<=pivot): i = i + 1 while(i<=j andarr[j]>=pivot): j = j - 1 if(j<i): flag= True else: temp= arr[i] arr[i] = arr[j] arr[j] = temp temp= arr[low]
  • 21. arr[low] = arr[j] arr[j] = temp returnj def quick_sort(arr,low,high): if(low<high): m=Partition(arr,low,high) quick_sort(arr,low,m-1) quick_sort(arr,m+1,high) def top_five(arr): print("Topfive score are : ") cnt = len(arr) if cnt < 5: start,stop = cnt - 1, -1 # stopset to -1 as we wantto print the 0th element else: start,stop = cnt - 1, cnt - 6 for i inrange(start,stop, -1): print("t{0:.2f}".format(arr[i]),end="") arr=[] Num=int(input("Enterthe numberof students:")) for i in range (Num): per=float(input("Enterthe marksof student"+ str(i+1) + " : "))
  • 22. arr.append(per) def main(): print("__________MENU__________") print("1.quick_sortsort") print("2.displaytopfive marks") print("3.exit") choice=int(input("enterchoice forsort:")) if choice==1: quick_sort(arr,0,Num-1) print("Sortedarray") print(arr) print() main() elif choice==2: top_five(arr) print() main() elif choice==3: exit else: print("entervalidinput") print(arr) main()