sidrs

FDS (LV) Ass 1

Jul 22nd, 2024 (edited)
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. secomp = []
  2. a = []
  3. b = []
  4. c = []
  5.  
  6. # FUNCTION FOR POPULATING LISTS
  7. def populate():
  8.     LIST1 = []
  9.     n = int(input("Enter the Number of Students: "))
  10.     print("Enter the Roll Numbers: ")
  11.     for i in range(0, n):
  12.         e = int(input())
  13.         LIST1.append(e)
  14.     return LIST1
  15.  
  16. # REMOVING DUPLICATES
  17. def removeDup(LIST1 = []):
  18.     TEMP = []
  19.     for i in LIST1:
  20.         if i not in TEMP:
  21.             TEMP.append(i)
  22.     return TEMP
  23.  
  24. # INTERSECTION
  25. def intersect(LIST1 = [], LIST2 = []):
  26.     RESULT = []
  27.     for i in LIST1:
  28.         if i in LIST2:
  29.             RESULT.append(i)
  30.     return RESULT
  31.  
  32. # UNION
  33. def uni(LIST1 = [], LIST2 = []):
  34.     RESULT = []
  35.     for i in LIST1:
  36.         RESULT.append(i)
  37.     for j in LIST2:
  38.         if j not in RESULT:
  39.             RESULT.append(j)
  40.     return RESULT
  41.  
  42.  
  43. # POPULATING THE LISTS
  44. print("---- Class Details ----")
  45. secomp = populate()
  46. secomp = removeDup(secomp)
  47. print ("\n ---- Group A: CRICKET ----")
  48. a = populate()
  49. a = removeDup(a)
  50. print("\n ---- Group B: BADMINTON ----")
  51. b = populate()
  52. b = removeDup(b)
  53. print("\n ---- Group C: FOOTBALL ----")
  54. c = populate()
  55. c = removeDup(c)
  56.  
  57.  
  58. print ("\n ---------- MENU ----------")
  59. while True:
  60.     print("\nChoose a Task Number from 1, 2, 3, 4, 5")
  61.     print("1: Get List of Students playing both Cricket and Badminton")
  62.     print("2: Get List of students playing either Cricket or Badminton but not both")
  63.     print("3: Get Number of students playing neither Cricket nor Badminton")
  64.     print("4: Get Number of students playing Cricket adn Football but not Badminton D")
  65.     print("5: Exit")
  66.     choice = int(input("Enter the Task Number: "))
  67.  
  68.     if choice == 1:
  69.         print("\nList of Students playing both Cricket and Badminton:")
  70.         AiB = intersect(a, b)
  71.         print(AiB)
  72.  
  73.     elif choice == 2:
  74.         print("\nList of students playing either Cricket or Badminton but not both:")
  75.         AiB = intersect(a, b)
  76.         AuB = uni(a, b)
  77.         XOR = []
  78.         for i in AuB:
  79.             if i not in AiB:
  80.                 XOR.append(i)
  81.         print(XOR)
  82.  
  83.     elif choice == 3:
  84.         print("\nGet Number of students playing neither Cricket nor Badminton:")
  85.         AuB = uni(a, b)
  86.         Req = []
  87.         for i in c:
  88.             if i not in AuB:
  89.                 Req.append(i)
  90.         print(len(Req))
  91.  
  92.    
  93.     elif choice == 4:
  94.         print("\nGet Number of students playing Cricket and Football but not Badminton:")
  95.         AiC = intersect(a, c)
  96.         Req = []
  97.         for i in AiC:
  98.             if i not in b:
  99.                 Req.append(i)
  100.         print(len(Req))
  101.  
  102.  
  103.     elif choice == 5:
  104.         break
  105.  
  106.     else:
  107.         print("Enter a Valid Task Number: (1, 2, 3, 4, 5)")
  108.  
Advertisement
Add Comment
Please, Sign In to add comment