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

Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfomprakashmeena48
 
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.pdfkarthikaparthasarath
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdfsrxerox
 
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.pdfrajatxyz
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3Abdul Haseeb
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdfsowmya koneru
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
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.pptxTseChris
 
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).pdfparthp5150s
 
calculator_new (1).pdf
calculator_new (1).pdfcalculator_new (1).pdf
calculator_new (1).pdfni30ji
 
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 2019Robert John
 

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

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

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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...Poonam Aher Patil
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
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 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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Ữ Â...Nguyen Thanh Tu Collection
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
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.docxRamakrishna Reddy Bijjam
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.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Ữ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 

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