Assignment 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

NAME : SIDDHARTH GANESH MARNE

ROLL NO : COSB49

Assignment No: 01
1 def accept_set(A,Str):
2 n = int(input("Enter the total no. of student who play %s :
3 "%Str))
4 for i in range(n) :
5 x = input("Enter the name of student %d who play %s : "%
6 ((i+1),Str))
7 A.append(x)
8 print("Set accepted successfully");
9
10 def display_set(A,Str):
11 n = len(A)
12 if(n == 0) :
13 print("\nGroup of Students who play %s = { }"%Str)
14 else :
15 print("\nGroup of Students who play %s = {"%Str,end=' ')
16 for i in range(n-1) :
17 print("%s,"%A[i],end=' ')
18 print("%s }"%A[n-1]);
19
20 def search_set(A,X) :
21 n = len(A)
22 for i in range(n):
23 if(A[i] == X) :
24 return (1)
25 return (0)
26
27
28 def find_intersection_set(A,B,C):
29 for i in range(len(A)):
30 flag = search_set(B,A[i]);
31 if(flag == 1) :
32 C.append(A[i])
33
34 def find_difference_set(A,B,C):
35 for i in range(len(A)):
36 flag = search_set(B,A[i]);
37 if(flag == 0) :
38 C.append(A[i])
39
40
41 def find_union_set(A,B,C):
42 for i in range(len(A)):
43 C.append(A[i])
44 for i in range(len(B)):
45 flag = search_set(A,B[i]);
46 if(flag == 0) :
47 C.append(B[i])
48
49 def Main() :

1
50 Group_A = []
51 Group_B = []
Group_C = []
52
53 while True :
54 print ("\t1 : Accept the Information")
print ("\t2 : List of students who play both cricket and
55 badminton")
print ("\t3 : List of students who play either cricket or
56 badminton but not both")
print ("\t4 : Number of students who play neither cricket nor
57 badminton")
print ("\t5 : Number of students who play cricket and
58 football but not badminton")
59 print ("\t6 : Exit")
60 ch = int(input("Enter your choice : "))
61 Group_R = []
62 if (ch == 6):
63 print ("End of Program")
64 break
65 elif (ch==1):
66 accept_set(Group_A,"Cricket")
67 accept_set(Group_B,"Badminton")
68 accept_set(Group_C,"Football")
69 display_set(Group_A,"Cricket")
70 display_set(Group_B,"Badminton")
71 display_set(Group_C,"Football")
72 elif (ch==2):
73 display_set(Group_A,"Cricket")
74 display_set(Group_B,"Badminton")
75 find_intersection_set(Group_A,Group_B,Group_R)
76 display_set(Group_R," both Cricket and Badminton")
77 elif (ch==3):
78 display_set(Group_A,"Cricket")
79 display_set(Group_B,"Badminton")
80 R1 = []
81 find_union_set(Group_A,Group_B,R1)
82 R2 = []
83 find_intersection_set(Group_A,Group_B,R2)
84 find_difference_set(R1,R2,Group_R)
85 display_set(Group_R," either cricket or badminton but not
both")
86 elif (ch==4):
87 display_set(Group_A,"Cricket")
88 display_set(Group_B,"Badminton")
89 display_set(Group_C,"Football")
90 R1 = []
91 find_union_set(Group_A,Group_B,R1)
92 find_difference_set(Group_C,R1,Group_R)
93 display_set(Group_R," neither cricket nor badminton")
94 print("Number of students who play neither cricket nor
badminton = %s"%len(Group_R))
95 elif (ch==5):
96 display_set(Group_A,"Cricket")
97 display_set(Group_C,"Football")
98 display_set(Group_B,"Badminton")
99 R1 = []

2
100 find_intersection_set(Group_A,Group_C,R1)
101 find_difference_set(R1,Group_B,Group_R)
102 display_set(Group_R,"cricket and football but not
badminton")
103 print("Number of students who play cricket and football
but not badminton = %s"%len(Group_R))
104 else :
105 print ("Wrong choice entered !! Try again")
106
107
108 Main()
109 quit()

You might also like