0% found this document useful (0 votes)
11 views3 pages

Fds Practical 2

Uploaded by

18limitededition
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Fds Practical 2

Uploaded by

18limitededition
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Roll No : 75

Assignment 2:

def removeDuplicate(d):
lst = []
for i in d:
if i not in lst:
lst.append(i)
return lst

def intersection(lst1, lst2):


return [val for val in lst1 if val in lst2]

def union(lst1, lst2):


lst3 = lst1.copy()
for val in lst2:
if val not in lst3:
lst3.append(val)
return lst3

def diff(lst1, lst2):


return [val for val in lst1 if val not in lst2]

def sym_diff(lst1, lst2):


return union(diff(lst1, lst2), diff(lst2, lst1))

def CB(lst1, lst2):


return intersection(lst1, lst2)

def eCeB(lst1, lst2):


return sym_diff(lst1, lst2)

def nCnB(lst1, lst2, lst3):


return diff(lst1, union(lst2, lst3))

def CBnF(lst1, lst2, lst3):


return diff(intersection(lst1, lst2), lst3)

SEComp = []
n = int(input("Enter number of students in SE COMP: "))
for _ in range(n):
SEComp.append(input())

Cricket = []
n = int(input("Enter number of students who play cricket: "))
for _ in range(n):
Cricket.append(input())
Cricket = removeDuplicate(Cricket)

Football = []
n = int(input("Enter number of students who play football: "))
for _ in range(n):
Football.append(input())
Football = removeDuplicate(Football)

Badminton = []
n = int(input("Enter number of students who play badminton: "))
for _ in range(n):
Badminton.append(input())
Badminton = removeDuplicate(Badminton)

while True:
print("\n1. 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 (1-5): "))

if ch == 1:
print("Students who play both cricket and badminton:", CB(Cricket, Badminton))
elif ch == 2:
print("Students who play either cricket or badminton but not both:", eCeB(Cricket, Badminton))
elif ch == 3:
print("Students who play neither cricket nor badminton:", nCnB(SEComp, Cricket, Badminton))
elif ch == 4:
print("Students who play cricket and football but not badminton:", CBnF(Cricket, Football,
Badminton))
elif ch == 5:
print("Thanks for using this program!")
break
else:
print("!!Wrong Choice!!")

OutPut :

Enter number of students in SE COMP: 5


Shivam
Deep
Om
Akash
Prasad
Enter number of students who play cricket: 2
Shivam
Dee
Enter number of students who play football: 3
Om
Akash
Shivam
Enter number of students who play badminton: 1
Deep

1. List of students who play both cricket and badminton


2. List of students who play either cricket or badminton but not both
3. Number of students who play neither cricket nor badminton
4. Number of students who play cricket and football but not badminton
5. Exit
Enter your Choice (1-5): 2
Students who play either cricket or badminton but not both: ['Shivam', 'Dee', 'Deep']
1. List of students who play both cricket and badminton
2. List of students who play either cricket or badminton but not both
3. Number of students who play neither cricket nor badminton
4. Number of students who play cricket and football but not badminton
5. Exit
Enter your Choice (1-5): 1
Students who play both cricket and badminton: []

1. List of students who play both cricket and badminton


2. List of students who play either cricket or badminton but not both
3. Number of students who play neither cricket nor badminton
4. Number of students who play cricket and football but not badminton
5. Exit
Enter your Choice (1-5): 4
Students who play cricket and football but not badminton: ['Shivam']

1. List of students who play both cricket and badminton


2. List of students who play either cricket or badminton but not both
3. Number of students who play neither cricket nor badminton
4. Number of students who play cricket and football but not badminton
5. Exit
Enter your Choice (1-5): 3
Students who play neither cricket nor badminton: ['Om', 'Akash', 'Prasad']

1. List of students who play both cricket and badminton


2. List of students who play either cricket or badminton but not both
3. Number of students who play neither cricket nor badminton
4. Number of students who play cricket and football but not badminton
5. Exit
Enter your Choice (1-5):5

You might also like