Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- secomp = []
- a = []
- b = []
- c = []
- # FUNCTION FOR POPULATING LISTS
- def populate():
- LIST1 = []
- n = int(input("Enter the Number of Students: "))
- print("Enter the Roll Numbers: ")
- for i in range(0, n):
- e = int(input())
- LIST1.append(e)
- return LIST1
- # REMOVING DUPLICATES
- def removeDup(LIST1 = []):
- TEMP = []
- for i in LIST1:
- if i not in TEMP:
- TEMP.append(i)
- return TEMP
- # INTERSECTION
- def intersect(LIST1 = [], LIST2 = []):
- RESULT = []
- for i in LIST1:
- if i in LIST2:
- RESULT.append(i)
- return RESULT
- # UNION
- def uni(LIST1 = [], LIST2 = []):
- RESULT = []
- for i in LIST1:
- RESULT.append(i)
- for j in LIST2:
- if j not in RESULT:
- RESULT.append(j)
- return RESULT
- # POPULATING THE LISTS
- print("---- Class Details ----")
- secomp = populate()
- secomp = removeDup(secomp)
- print ("\n ---- Group A: CRICKET ----")
- a = populate()
- a = removeDup(a)
- print("\n ---- Group B: BADMINTON ----")
- b = populate()
- b = removeDup(b)
- print("\n ---- Group C: FOOTBALL ----")
- c = populate()
- c = removeDup(c)
- print ("\n ---------- MENU ----------")
- while True:
- print("\nChoose a Task Number from 1, 2, 3, 4, 5")
- print("1: Get List of Students playing both Cricket and Badminton")
- print("2: Get List of students playing either Cricket or Badminton but not both")
- print("3: Get Number of students playing neither Cricket nor Badminton")
- print("4: Get Number of students playing Cricket adn Football but not Badminton D")
- print("5: Exit")
- choice = int(input("Enter the Task Number: "))
- if choice == 1:
- print("\nList of Students playing both Cricket and Badminton:")
- AiB = intersect(a, b)
- print(AiB)
- elif choice == 2:
- print("\nList of students playing either Cricket or Badminton but not both:")
- AiB = intersect(a, b)
- AuB = uni(a, b)
- XOR = []
- for i in AuB:
- if i not in AiB:
- XOR.append(i)
- print(XOR)
- elif choice == 3:
- print("\nGet Number of students playing neither Cricket nor Badminton:")
- AuB = uni(a, b)
- Req = []
- for i in c:
- if i not in AuB:
- Req.append(i)
- print(len(Req))
- elif choice == 4:
- print("\nGet Number of students playing Cricket and Football but not Badminton:")
- AiC = intersect(a, c)
- Req = []
- for i in AiC:
- if i not in b:
- Req.append(i)
- print(len(Req))
- elif choice == 5:
- break
- else:
- print("Enter a Valid Task Number: (1, 2, 3, 4, 5)")
Advertisement
Add Comment
Please, Sign In to add comment