119 lines
3.5 KiB
Python
119 lines
3.5 KiB
Python
Uni = []
|
|
n = int(input("Enter number of students: "))
|
|
for i in range(0,n):
|
|
element = input()
|
|
Uni.append(element)
|
|
print(Uni)
|
|
cricket = []
|
|
b = int(input("Enter number students who play cricket: "))
|
|
for j in range(0,b):
|
|
ele=input()
|
|
cricket.append(ele)
|
|
print(cricket)
|
|
bad = []
|
|
c = int(input("Enter number students who play badminton: "))
|
|
for k in range(0,c):
|
|
elem=input()
|
|
bad.append(elem)
|
|
print(bad)
|
|
foot = []
|
|
d = int(input("Enter number students who play football: "))
|
|
for j in range(0,d):
|
|
eleme=input()
|
|
foot.append(eleme)
|
|
print(foot)
|
|
|
|
def CB():
|
|
list3 = intersection(cricket,bad)
|
|
print("Names of common students who play cricket and badminton: ", list3)
|
|
print("Number of students who play cricket and badminton: ",len(list3))
|
|
|
|
def CF():
|
|
list3 = intersection(cricket,foot)
|
|
print("Names of common students who play cricket and football: ", list3)
|
|
print("Number of students who play cricket and football: ",len(list3))
|
|
|
|
def BF():
|
|
list3 = intersection(bad,foot)
|
|
print("Names of common students who play football and badminton: ", list3)
|
|
print("Number of students who play badminton and football: ",len(list3))
|
|
|
|
def intersection(list1,list2):
|
|
list3=[]
|
|
for val in list1:
|
|
if val in list2:
|
|
list3.append(val)
|
|
return list3
|
|
|
|
def eCeB():
|
|
D1=diff(cricket,bad)
|
|
D2=diff(bad,cricket)
|
|
# print("C-B = ",D1)
|
|
# print("B-C = ",D2)
|
|
DUB=union(D1,D2)
|
|
print("People who play either cricket or badminton but not both: ",DUB)
|
|
def eCeF():
|
|
D1=diff(cricket,foot)
|
|
D2=diff(foot,cricket)
|
|
# print("C-B = ",D1)
|
|
# print("B-C = ",D2)
|
|
DUB=union(D1,D2)
|
|
print("People who play either cricket or football but not both: ",DUB)
|
|
def eFeB():
|
|
D1=diff(foot,bad)
|
|
D2=diff(bad,foot)
|
|
# print("C-B = ",D1)
|
|
# print("B-C = ",D2)
|
|
DUB=union(D1,D2)
|
|
print("People who play either football or badminton but not both: ",DUB)
|
|
def diff(list1, list2):
|
|
list3 = []
|
|
for val in list1:
|
|
if val not in list2:
|
|
list3.append(val)
|
|
return list3
|
|
def union(list1,list2):
|
|
list3 = list1.copy()
|
|
for val in list2:
|
|
if val not in list3:
|
|
list3.append(val)
|
|
return list3
|
|
def nCnB():
|
|
list4 = diff(Uni,union(cricket,bad))
|
|
print("Students who play neither cricket nor badminton: ",len(list4))
|
|
def nCnF():
|
|
list4 = diff(Uni,union(cricket,foot))
|
|
print("Students who play neither cricket nor football: ",len(list4))
|
|
def nFnB():
|
|
list4 = diff(Uni,union(foot,bad))
|
|
print("Students who play neither football nor badminton: ",len(list4))
|
|
def pCpF():
|
|
list4 = intersection(cricket,foot)
|
|
list5 = diff(list4,bad)
|
|
print("People who play cricket and football but not badminton: ", len(list5))
|
|
def pCpB():
|
|
list4 = intersection(cricket,bad)
|
|
list5 = diff(list4,foot)
|
|
print("People who play cricket and badminton but not football: ",len(list5))
|
|
def pBpF():
|
|
list4 = intersection(foot,bad)
|
|
list5 = diff(list4,cricket)
|
|
print("People who play badminton and football but not cricket: ",len(list5))
|
|
flag = 1
|
|
while flag == 1:
|
|
print("1. List of students who play both cricket and badminton: ")
|
|
print("2. List of students who play either cricket or badminton but not football: ")
|
|
print("3. Number of students who play neither cricket not badminton: ")
|
|
print("4. Number of students who play cricket and football but not badmitnon: ")
|
|
print("5. Exit")
|
|
ch = int(input("Enter your choice: "))
|
|
if(ch == 1):
|
|
CB()
|
|
elif(ch == 2):
|
|
eCeB()
|
|
elif(ch == 3):
|
|
nCnB()
|
|
elif(ch == 4):
|
|
pCpF()
|
|
else:
|
|
flag = 0 |