SlideShare a Scribd company logo
1 of 22
Download to read offline
Practicle 1
def accept_set(A,Str):
n = int(input("Enter the total no. of student who play %s : "%Str))
for i in range(n) :
x = input("Enter the name of student %d who play %s : "%((i+1),Str))
A.append(x)
print("Set accepted successfully");
def display_set(A,Str):
n = len(A)
if(n == 0) :
print("nGroup of Students who play %s = { }"%Str)
else :
print("nGroup of Students who play %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 in range(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 in range(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 : List of students who play both cricket and badminton")
print ("2 : List of students who play either cricket or badminton but not both")
print ("3 : Number of students who play neither cricket nor badminton")
print ("4 : Number of students who play cricket and football but not badminton")
print ("5 : Exit")
ch = int(input("Enter your choice : "))
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," both Cricket and Badminton")
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," either cricket or badminton but not both")
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," neither cricket nor badminton")
print("Number of students who play neither cricket nor badminton = %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,"cricket and football but not badminton")
print("Number of students who play cricket and football but not badminton = %s"%len(Group_R))
print()
main()
elif (ch==5):
exit
else :
print ("Wrong choice entered !! Try again")
main()
practicle 2
# The average_score score of class
def average_score(l):
sum = 0
cnt = 0
for i in range(len(l)):
if l[i] != -1:
sum += l[i]
cnt += 1
avg = sum / cnt
print("Total Marks are : ", sum)
print("average_score Marks are : {:.2f}".format(avg))
# Highest score in the class
def highest_score(l):
Max = l[0]
for i in range(len(l)):
if l[i] > Max:
Max = l[i]
return (Max)
# Lowest score in the class
def lowest_score(l):
# Assign first element in the array which corresponds to marks of first present student
# This for loop ensures the above condition
for i in range(len(l)):
if l[i] != -1:
Min = l[i]
break
for j in range(i + 1, len(l)):
if l[j] != -1 and l[j] < Min:
Min = l[j]
return (Min)
# Count of students who were absent for the test
def absent_student(l):
cnt = 0
for i in range(len(l)):
if l[i] == -1:
cnt += 1
return (cnt)
# Display mark with highest frequency
# refeence link : https://www.youtube.com/watch?v=QrIXGqvvpk4&t=422s
def highest_frequancy(l):
i = 0
Max = 0
print(" Marks ----> frequency count ")
for ele in l:
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)
# Input the number of students and their corresponding marks in FDS
student_marks = []
noStudents = int(input("Enter total number of students : "))
for i in range(noStudents):
marks = int(input("Enter marks of Student " + str(i + 1) + " : "))
student_marks.append(marks)
def main():
print("tt__________MENU_________")
print("1. The average_score score of class ")
print("2. Highest score and lowest score of class ")
print("3. Count of students who were absent for the test ")
print("4. Display mark with highest frequency ")
print("5. Exit ")
choice = int(input("Enter your choice : "))
if choice == 1:
average_score(student_marks)
print()
main()
elif choice == 2:
print("Highest score in the class is : ", highest_score(student_marks))
print("Lowest score in the class is : ", lowest_score(student_marks))
print()
main()
elif choice == 3:
print("Count of students who were absent for the test is : ", absent_student(student_marks))
print()
main()
elif choice == 4:
mark, count = highest_frequancy(student_marks)
print("Highest frequency of marks {0} is {1} ".format(mark, count))
print()
main()
elif choice == 5:
exit
else:
print("Wrong choice")
print()
main()
practicle 3
print("basic matrix operation using python")
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("enter the number of rows and colums")
row1=int(input("enter no of rows in first matrix:"))
col1=int(input("enter no of column in first matrix:"))
row2=int(input("enter no of rows in second matrix:"))
col2=int(input("enter no of rows in second matrix:"))
def main():
print("1. addition of two matrix")
print("2. subtraction of two matrix ")
print("3. multiplication of two matrix")
print("4. transpose of first matrix")
print("5. transpose of second matrix")
print("6. exit")
choice =int(input("enter your choice:"))
if choice==1:
print(" addition of two matrix" )
if ((row1==row2)and (col1==col2)):
matrix_addition(m1,m2,row1,col1)
show_matrix(res,row1,col1)
else:
print("addition is not possible")
print()
main()
elif choice==2:
print(" subtraction of two matrix" )
if ((row1==row2)and (col1==col2)):
matrix_subtraction(m1,m2,row1,col1)
show_matrix(res,row1,col1)
else:
print("subtraction is not possible")
print()
main()
elif choice==3:
print("multiplication of matrix")
if (col1==row2):
matrix_multiplication(m1,m2,row2,col1)
show_matrix(res,row2,col1)
else:
print("multiplication is not possible")
print()
main()
elif choice==4:
print("after applying transpose matrix elemnt are:")
matrix_transpose(m1,row1,col1)
show_matrix(res, row1,col1)
print()
main()
elif choice==5:
print("after applying transpose matrix elemnt are:")
matrix_transpose(m1,row1,col1)
show_matrix(res, row2,col2)
print()
main()
elif choice==6:
exit
else:
print("enter valid choice")
def accept_matrix(m,row,col):
for i in range (row):
c=[]
for j in range(col):
no=int(input("enter the value of matrix[" + str(i) + "] [" + str(j) + "]::"))
c.append(no)
print("-----------------")
m.append(c)
print("enter the value of for first matrix")
accept_matrix(m1,row1,col1)
print("enter the value for second matrix")
accept_matrix(m2,row2,col2)
def show_matrix(m,row,col):
for i in range(row):
for j in range(col):
print(m[i][j],end=" ")
print()
# show_matrix matrix
print("the first matrix is:")
show_matrix(m1,row1,col1)
print("the second matrix :")
show_matrix(m2,row2,col2)
def matrix_addition(m1,m2,row,col):
for i in range(row):
for j in range(col):
res[i][j]=m1[i][j]+m2[i][j]
def matrix_subtraction(m1,m2,row,col):
for i in range(row):
for j in range(col):
res[i][j]=m1[i][j] - m2[i][j]
def matrix_multiplication(m1,m2,row,col):
for i in range (row):
for j in range(col):
for k in range(col):
res[i][j]=res[i][j]+m1[i][k]*m2[k][j]
def matrix_transpose(m,row,col):
for i in range (row):
for j in range(col):
res[i][j]= m[j][i]
main()
practicle 4
#-----------------------------------------------
"""
Write a python program to store first year percentage of students in array.
Write function for sorting array of floating point numbers in ascending order using
a) Selection Sort
b) Bubble sort and display top five scores.
"""
def bubbleSort(arr):
n = len(arr)
for i in range(n-1):
for j in range(0, n-i-1):
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
def selectionSort(arr):
for i in range(len(arr)):
min_idx = i
for j in range(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("Top five score are : ")
cnt = len(arr)
if cnt < 5:
start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element
else:
start, stop = cnt - 1, cnt - 6
for i in range(start, stop, -1):
print("t {0:.2f}".format(arr[i]), end=" ")
arr=[]
Num=int(input("Enter the number of students: "))
for i in range (Num):
per=float(input("Enter the marks of student " + str(i+1) + " : "))
arr.append(per)
def main():
print("1. selection sort")
print("2. bubble sort")
print("3. display top five marks")
print("4. exit")
choice=int(input("enter choice for sort:"))
if choice==1:
selectionSort(arr)
print ("Sorted array")
m=[]
for i in range(len(arr)):
m.append(arr)
print(m)
break
print()
main()
elif choice==2:
bubbleSort(arr)
print ("Sorted array is:")
n=[]
for i in range(len(arr)):
n.append(arr)
print(n)
break
main()
elif choice==3:
top_five(arr)
elif choice==4:
exit
else:
print("enter valid input")
print(arr)
main()
practicle 5
"""
Write a python program to store first year percentage of students in array.
Write function for sorting array of floating point numbers in ascending order using
a) shell sort
b) Insertion sort and display top five scores.
"""
def shellSort(arr):
n = len(arr)
gap = n // 2
# Do a gapped insertion_sort for this gap size.
# The first gap elements a[0..gap-1] are already in gapped
# order keep adding one more element until the entire array
# is gap sorted
while gap > 0:
for i in range(gap, n):
# add arr[i] to the elements that have been gap sorted
# save arr[i] in temp and make a hole at position i
temp = arr[i]
# shift earlier gap-sorted elements up until the correct
# location for arr[i] is found
j = i
while j >= gap and arr[j - gap] > temp:
arr[j] = arr[j - gap]
j -= gap
# put temp (the original arr[i]) in its correct location
arr[j] = temp
gap //= 2
return arr
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
# Move elements of a[0..i-1], that are
# greater than key, to one position ahead
# of their current position
j = i - 1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr
def top_five(arr):
print("Top five score are : ")
cnt = len(arr)
if cnt < 5:
start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element
else:
start, stop = cnt - 1, cnt - 6
for i in range(start, stop, -1):
print("t {0:.2f}".format(arr[i]), end=" ")
arr=[]
Num=int(input("Enter the number of students: "))
for i in range (Num):
per=float(input("Enter the marks of student " + str(i+1) + " : "))
arr.append(per)
def main():
print("1. shell sort")
print("2. insertion sort")
print("3. display top five marks")
print("4. exit")
choice=int(input("enter choice for sort:"))
if choice==1:
insertion_sort(arr)
print ("Sorted array")
m=[]
for i in range(len(arr)):
m.append(arr)
print(m)
break
print()
main()
elif choice==2:
shellSort(arr)
print ("Sorted array is:")
n=[]
for i in range(len(arr)):
n.append(arr)
print(n)
break
main()
elif choice==3:
top_five(arr)
elif choice==4:
exit
else:
print("enter valid input")
print(arr)
main()
practicle 6
#-----------------------------------------------
"""
Write a python program to store first year percentage of students in array.
Write function for sorting array of floating point numbers in ascending order using
a) quick_sort sort display top five scores.
"""
print("tt______________PROGRAM_____________")
print()
def Partition(arr,low,high):
pivot = arr[low]
i=low+1
j=high
flag = False
while(not flag):
while(i<=j and arr[i]<=pivot):
i = i + 1
while(i<=j and arr[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
return j
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("Top five score are : ")
cnt = len(arr)
if cnt < 5:
start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element
else:
start, stop = cnt - 1, cnt - 6
for i in range(start, stop, -1):
print("t {0:.2f}".format(arr[i]), end=" ")
arr=[]
Num=int(input("Enter the number of students: "))
for i in range (Num):
per=float(input("Enter the marks of student " + str(i+1) + " : "))
arr.append(per)
def main():
print("__________MENU__________")
print("1. quick_sort sort")
print("2. display top five marks")
print("3. exit")
choice=int(input("enter choice for sort:"))
if choice==1:
quick_sort(arr,0,Num-1)
print ("Sorted array")
print(arr)
print()
main()
elif choice==2:
top_five(arr)
print()
main()
elif choice==3:
exit
else:
print("enter valid input")
print(arr)
main()

More Related Content

Similar to fds Practicle 1to 6 program.pdf

Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 

Similar to fds Practicle 1to 6 program.pdf (20)

Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
Python Programming
Python Programming Python Programming
Python Programming
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Python 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptxPython 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptx
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
calculator_new (1).pdf
calculator_new (1).pdfcalculator_new (1).pdf
calculator_new (1).pdf
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
 
Baby Steps to Machine Learning at DevFest Lagos 2019
Baby Steps to Machine Learning at DevFest Lagos 2019Baby Steps to Machine Learning at DevFest Lagos 2019
Baby Steps to Machine Learning at DevFest Lagos 2019
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
xii cs practicals
xii cs practicalsxii cs practicals
xii cs practicals
 

More from GaneshPawar819187 (6)

DSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdfDSA Presentetion Huffman tree.pdf
DSA Presentetion Huffman tree.pdf
 
dsa pract 2.pdf
dsa pract 2.pdfdsa pract 2.pdf
dsa pract 2.pdf
 
Doc3.docx
Doc3.docxDoc3.docx
Doc3.docx
 
fds u1.docx
fds u1.docxfds u1.docx
fds u1.docx
 
Dsa pract1.docx
Dsa pract1.docxDsa pract1.docx
Dsa pract1.docx
 
dsa pract 2.docx
dsa pract 2.docxdsa pract 2.docx
dsa pract 2.docx
 

Recently uploaded

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

fds Practicle 1to 6 program.pdf

  • 1. Practicle 1 def accept_set(A,Str): n = int(input("Enter the total no. of student who play %s : "%Str)) for i in range(n) : x = input("Enter the name of student %d who play %s : "%((i+1),Str)) A.append(x) print("Set accepted successfully"); def display_set(A,Str): n = len(A) if(n == 0) : print("nGroup of Students who play %s = { }"%Str) else : print("nGroup of Students who play %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 in range(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 in range(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 : List of students who play both cricket and badminton") print ("2 : List of students who play either cricket or badminton but not both") print ("3 : Number of students who play neither cricket nor badminton") print ("4 : Number of students who play cricket and football but not badminton") print ("5 : Exit") ch = int(input("Enter your choice : ")) 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," both Cricket and Badminton") 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," either cricket or badminton but not both") 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," neither cricket nor badminton") print("Number of students who play neither cricket nor badminton = %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,"cricket and football but not badminton") print("Number of students who play cricket and football but not badminton = %s"%len(Group_R)) print() main() elif (ch==5): exit else : print ("Wrong choice entered !! Try again")
  • 5. main() practicle 2 # The average_score score of class def average_score(l): sum = 0 cnt = 0 for i in range(len(l)): if l[i] != -1: sum += l[i] cnt += 1 avg = sum / cnt print("Total Marks are : ", sum) print("average_score Marks are : {:.2f}".format(avg)) # Highest score in the class def highest_score(l): Max = l[0] for i in range(len(l)): if l[i] > Max: Max = l[i] return (Max)
  • 6. # Lowest score in the class def lowest_score(l): # Assign first element in the array which corresponds to marks of first present student # This for loop ensures the above condition for i in range(len(l)): if l[i] != -1: Min = l[i] break for j in range(i + 1, len(l)): if l[j] != -1 and l[j] < Min: Min = l[j] return (Min) # Count of students who were absent for the test def absent_student(l): cnt = 0 for i in range(len(l)): if l[i] == -1: cnt += 1 return (cnt)
  • 7. # Display mark with highest frequency # refeence link : https://www.youtube.com/watch?v=QrIXGqvvpk4&t=422s def highest_frequancy(l): i = 0 Max = 0 print(" Marks ----> frequency count ") for ele in l: 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) # Input the number of students and their corresponding marks in FDS student_marks = [] noStudents = int(input("Enter total number of students : ")) for i in range(noStudents): marks = int(input("Enter marks of Student " + str(i + 1) + " : ")) student_marks.append(marks) def main(): print("tt__________MENU_________") print("1. The average_score score of class ") print("2. Highest score and lowest score of class ")
  • 8. print("3. Count of students who were absent for the test ") print("4. Display mark with highest frequency ") print("5. Exit ") choice = int(input("Enter your choice : ")) if choice == 1: average_score(student_marks) print() main() elif choice == 2: print("Highest score in the class is : ", highest_score(student_marks)) print("Lowest score in the class is : ", lowest_score(student_marks)) print() main() elif choice == 3: print("Count of students who were absent for the test is : ", absent_student(student_marks)) print() main() elif choice == 4: mark, count = highest_frequancy(student_marks) print("Highest frequency of marks {0} is {1} ".format(mark, count)) print() main() elif choice == 5: exit else: print("Wrong choice")
  • 9. print() main() practicle 3 print("basic matrix operation using python") 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("enter the number of rows and colums") row1=int(input("enter no of rows in first matrix:")) col1=int(input("enter no of column in first matrix:")) row2=int(input("enter no of rows in second matrix:")) col2=int(input("enter no of rows in second matrix:")) def main(): print("1. addition of two matrix") print("2. subtraction of two matrix ") print("3. multiplication of two matrix") print("4. transpose of first matrix") print("5. transpose of second matrix") print("6. exit") choice =int(input("enter your choice:"))
  • 10. if choice==1: print(" addition of two matrix" ) if ((row1==row2)and (col1==col2)): matrix_addition(m1,m2,row1,col1) show_matrix(res,row1,col1) else: print("addition is not possible") print() main() elif choice==2: print(" subtraction of two matrix" ) if ((row1==row2)and (col1==col2)): matrix_subtraction(m1,m2,row1,col1) show_matrix(res,row1,col1) else: print("subtraction is not possible") print() main() elif choice==3: print("multiplication of matrix") if (col1==row2): matrix_multiplication(m1,m2,row2,col1) show_matrix(res,row2,col1) else: print("multiplication is not possible") print() main() elif choice==4:
  • 11. print("after applying transpose matrix elemnt are:") matrix_transpose(m1,row1,col1) show_matrix(res, row1,col1) print() main() elif choice==5: print("after applying transpose matrix elemnt are:") matrix_transpose(m1,row1,col1) show_matrix(res, row2,col2) print() main() elif choice==6: exit else: print("enter valid choice") def accept_matrix(m,row,col): for i in range (row): c=[] for j in range(col): no=int(input("enter the value of matrix[" + str(i) + "] [" + str(j) + "]::")) c.append(no) print("-----------------") m.append(c) print("enter the value of for first matrix")
  • 12. accept_matrix(m1,row1,col1) print("enter the value for second matrix") accept_matrix(m2,row2,col2) def show_matrix(m,row,col): for i in range(row): for j in range(col): print(m[i][j],end=" ") print() # show_matrix matrix print("the first matrix is:") show_matrix(m1,row1,col1) print("the second matrix :") show_matrix(m2,row2,col2) def matrix_addition(m1,m2,row,col): for i in range(row): for j in range(col): res[i][j]=m1[i][j]+m2[i][j] def matrix_subtraction(m1,m2,row,col): for i in range(row): for j in range(col): res[i][j]=m1[i][j] - m2[i][j] def matrix_multiplication(m1,m2,row,col): for i in range (row): for j in range(col):
  • 13. for k in range(col): res[i][j]=res[i][j]+m1[i][k]*m2[k][j] def matrix_transpose(m,row,col): for i in range (row): for j in range(col): res[i][j]= m[j][i] main() practicle 4 #----------------------------------------------- """ Write a python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) Selection Sort b) Bubble sort and display top five scores. """ def bubbleSort(arr): n = len(arr) for i in range(n-1): for j in range(0, n-i-1): if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j]
  • 14. def selectionSort(arr): for i in range(len(arr)): min_idx = i for j in range(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("Top five score are : ") cnt = len(arr) if cnt < 5: start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element else: start, stop = cnt - 1, cnt - 6 for i in range(start, stop, -1): print("t {0:.2f}".format(arr[i]), end=" ") arr=[] Num=int(input("Enter the number of students: ")) for i in range (Num): per=float(input("Enter the marks of student " + str(i+1) + " : ")) arr.append(per)
  • 15. def main(): print("1. selection sort") print("2. bubble sort") print("3. display top five marks") print("4. exit") choice=int(input("enter choice for sort:")) if choice==1: selectionSort(arr) print ("Sorted array") m=[] for i in range(len(arr)): m.append(arr) print(m) break print() main() elif choice==2: bubbleSort(arr) print ("Sorted array is:") n=[] for i in range(len(arr)): n.append(arr) print(n) break main() elif choice==3: top_five(arr)
  • 16. elif choice==4: exit else: print("enter valid input") print(arr) main() practicle 5 """ Write a python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) shell sort b) Insertion sort and display top five scores. """ def shellSort(arr): n = len(arr) gap = n // 2 # Do a gapped insertion_sort for this gap size. # The first gap elements a[0..gap-1] are already in gapped # order keep adding one more element until the entire array # is gap sorted while gap > 0: for i in range(gap, n): # add arr[i] to the elements that have been gap sorted
  • 17. # save arr[i] in temp and make a hole at position i temp = arr[i] # shift earlier gap-sorted elements up until the correct # location for arr[i] is found j = i while j >= gap and arr[j - gap] > temp: arr[j] = arr[j - gap] j -= gap # put temp (the original arr[i]) in its correct location arr[j] = temp gap //= 2 return arr def insertion_sort(arr): for i in range(1, len(arr)): key = arr[i] # Move elements of a[0..i-1], that are # greater than key, to one position ahead # of their current position j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr
  • 18. def top_five(arr): print("Top five score are : ") cnt = len(arr) if cnt < 5: start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element else: start, stop = cnt - 1, cnt - 6 for i in range(start, stop, -1): print("t {0:.2f}".format(arr[i]), end=" ") arr=[] Num=int(input("Enter the number of students: ")) for i in range (Num): per=float(input("Enter the marks of student " + str(i+1) + " : ")) arr.append(per) def main(): print("1. shell sort") print("2. insertion sort") print("3. display top five marks") print("4. exit") choice=int(input("enter choice for sort:")) if choice==1:
  • 19. insertion_sort(arr) print ("Sorted array") m=[] for i in range(len(arr)): m.append(arr) print(m) break print() main() elif choice==2: shellSort(arr) print ("Sorted array is:") n=[] for i in range(len(arr)): n.append(arr) print(n) break main() elif choice==3: top_five(arr) elif choice==4: exit else: print("enter valid input") print(arr) main()
  • 20. practicle 6 #----------------------------------------------- """ Write a python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) quick_sort sort display top five scores. """ print("tt______________PROGRAM_____________") print() def Partition(arr,low,high): pivot = arr[low] i=low+1 j=high flag = False while(not flag): while(i<=j and arr[i]<=pivot): i = i + 1 while(i<=j and arr[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 return j 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("Top five score are : ") cnt = len(arr) if cnt < 5: start, stop = cnt - 1, -1 # stop set to -1 as we want to print the 0th element else: start, stop = cnt - 1, cnt - 6 for i in range(start, stop, -1): print("t {0:.2f}".format(arr[i]), end=" ") arr=[] Num=int(input("Enter the number of students: ")) for i in range (Num): per=float(input("Enter the marks of student " + str(i+1) + " : "))
  • 22. arr.append(per) def main(): print("__________MENU__________") print("1. quick_sort sort") print("2. display top five marks") print("3. exit") choice=int(input("enter choice for sort:")) if choice==1: quick_sort(arr,0,Num-1) print ("Sorted array") print(arr) print() main() elif choice==2: top_five(arr) print() main() elif choice==3: exit else: print("enter valid input") print(arr) main()