SlideShare a Scribd company logo
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

Similar to Practicle 1.docx (20)

DOCX
Recursion in C
Lakshmi Sarvani Videla
 
DOCX
ECE-PYTHON.docx
Chaithanya89350
 
PPT
Struct examples
mondalakash2012
 
PPT
array.ppt
DeveshDewangan5
 
PPTX
Python Statistics.pptx
MalathiNagarajan5
 
DOCX
Basic python laboratoty_ PSPP Manual .docx
Kirubaburi R
 
PDF
Xi CBSE Computer Science lab programs
Prof. Dr. K. Adisesha
 
PPTX
one dimentional array on programming with C
AlySaeed10
 
PDF
Quantum simulation Mathematics and Python examples
RaviSankar637310
 
PDF
Baby Steps to Machine Learning at DevFest Lagos 2019
Robert John
 
DOCX
Ml all programs
adnaanmohamed
 
PDF
Algorithm Design and Analysis - Practical File
KushagraChadha1
 
PDF
data structure and algorithm.pdf
Asrinath1
 
DOCX
Aastha Shah.docx
AasthaShah41
 
PPT
All important c programby makhan kumbhkar
sandeep kumbhkar
 
PDF
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
PDF
Kotlin for Android Developers - 2
Mohamed Nabil, MSc.
 
PDF
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
DOCX
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 
PDF
xii cs practicals
JaswinderKaurSarao
 
Recursion in C
Lakshmi Sarvani Videla
 
ECE-PYTHON.docx
Chaithanya89350
 
Struct examples
mondalakash2012
 
array.ppt
DeveshDewangan5
 
Python Statistics.pptx
MalathiNagarajan5
 
Basic python laboratoty_ PSPP Manual .docx
Kirubaburi R
 
Xi CBSE Computer Science lab programs
Prof. Dr. K. Adisesha
 
one dimentional array on programming with C
AlySaeed10
 
Quantum simulation Mathematics and Python examples
RaviSankar637310
 
Baby Steps to Machine Learning at DevFest Lagos 2019
Robert John
 
Ml all programs
adnaanmohamed
 
Algorithm Design and Analysis - Practical File
KushagraChadha1
 
data structure and algorithm.pdf
Asrinath1
 
Aastha Shah.docx
AasthaShah41
 
All important c programby makhan kumbhkar
sandeep kumbhkar
 
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
Kotlin for Android Developers - 2
Mohamed Nabil, MSc.
 
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 
xii cs practicals
JaswinderKaurSarao
 

More from GaneshPawar819187 (6)

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

Recently uploaded (20)

PPTX
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
PPTX
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
PPTX
Room booking management - Meeting Room In Odoo 17
Celine George
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
FAMILY HEALTH NURSING CARE - UNIT 5 - CHN 1 - GNM 1ST YEAR.pptx
Priyanshu Anand
 
PDF
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
PPTX
How to Manage Resupply Subcontracting in Odoo 18
Celine George
 
PPTX
HIRSCHSPRUNG'S DISEASE(MEGACOLON): NURSING MANAGMENT.pptx
PRADEEP ABOTHU
 
PPTX
Company - Meaning - Definition- Types of Company - Incorporation of Company
DevaRam6
 
PDF
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PDF
water conservation .pdf by Nandni Kumari XI C
Directorate of Education Delhi
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
PPTX
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
PDF
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
PDF
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
PPTX
MALABSORPTION SYNDROME: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
PPTX
ARAL Program of Adia Elementary School--
FatimaAdessaPanaliga
 
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
IDEAS AND EARLY STATES Social science pptx
NIRANJANASSURESH
 
Room booking management - Meeting Room In Odoo 17
Celine George
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
FAMILY HEALTH NURSING CARE - UNIT 5 - CHN 1 - GNM 1ST YEAR.pptx
Priyanshu Anand
 
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
How to Manage Resupply Subcontracting in Odoo 18
Celine George
 
HIRSCHSPRUNG'S DISEASE(MEGACOLON): NURSING MANAGMENT.pptx
PRADEEP ABOTHU
 
Company - Meaning - Definition- Types of Company - Incorporation of Company
DevaRam6
 
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
water conservation .pdf by Nandni Kumari XI C
Directorate of Education Delhi
 
Constitutional Design Civics Class 9.pptx
bikesh692
 
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
MALABSORPTION SYNDROME: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
ARAL Program of Adia Elementary School--
FatimaAdessaPanaliga
 
Ad

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()