A5 added
This commit is contained in:
parent
b7b5524006
commit
59ca3ebb01
@ -1,119 +0,0 @@
|
|||||||
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
|
|
@ -1,80 +0,0 @@
|
|||||||
NoOfStudents = int(input("Enter number of students: "))
|
|
||||||
list1 = []
|
|
||||||
list2 = []
|
|
||||||
for i in range(0,NoOfStudents):
|
|
||||||
n = float(input("Enter student percentage: "))
|
|
||||||
list2.append(n)
|
|
||||||
for j in list2:
|
|
||||||
if(j != -1):
|
|
||||||
list1.append(j)
|
|
||||||
|
|
||||||
def avg():
|
|
||||||
sum1 = 0
|
|
||||||
for i in list1:
|
|
||||||
sum1 = sum1 + i
|
|
||||||
avg = sum1/NoOfStudents
|
|
||||||
print("Sum is: ",sum1)
|
|
||||||
print("Average is: ",avg)
|
|
||||||
|
|
||||||
def largest():
|
|
||||||
largest = None
|
|
||||||
for i in list1:
|
|
||||||
if(largest==None or largest<i):
|
|
||||||
largest = i
|
|
||||||
print("The highest marks is: ",largest)
|
|
||||||
|
|
||||||
def smallest():
|
|
||||||
smallest = None
|
|
||||||
for i in list1:
|
|
||||||
if(smallest==None or smallest>i):
|
|
||||||
smallest = i
|
|
||||||
print("The lowest marks is: ",smallest)
|
|
||||||
|
|
||||||
def absent():
|
|
||||||
abs = 0
|
|
||||||
for j in list2:
|
|
||||||
if(j == -1):
|
|
||||||
abs = abs + 1
|
|
||||||
print("Number of absent students are: ",abs)
|
|
||||||
|
|
||||||
def frequency():
|
|
||||||
temp = 0
|
|
||||||
for i in list1:
|
|
||||||
max1 = 0
|
|
||||||
for j in range(0,len(list1)):
|
|
||||||
if(i == list1[j]):
|
|
||||||
max1 = max1 + 1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
if(max1>temp):
|
|
||||||
temp = max1
|
|
||||||
k = i
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
print("Marks with highest frequency is: ",k)
|
|
||||||
print("Frequency of the number is: ",temp)
|
|
||||||
|
|
||||||
flag = 1
|
|
||||||
while flag == 1:
|
|
||||||
print("\nThe options are: ")
|
|
||||||
print("1. Total and average marks are: ")
|
|
||||||
print("2. Highest marks among the students: ")
|
|
||||||
print("3. Lowest marks among the students: ")
|
|
||||||
print("4. Number of absent students: ")
|
|
||||||
print("5. Marks with highest frequency is: ")
|
|
||||||
print("6. Exit")
|
|
||||||
ch = int(input("Enter choice: "))
|
|
||||||
if(ch == 1):
|
|
||||||
avg()
|
|
||||||
elif(ch == 2):
|
|
||||||
largest()
|
|
||||||
elif(ch == 3):
|
|
||||||
smallest()
|
|
||||||
elif(ch == 4):
|
|
||||||
absent()
|
|
||||||
elif(ch == 5):
|
|
||||||
frequency()
|
|
||||||
elif(ch == 6):
|
|
||||||
flag = 0
|
|
||||||
elif(ch>6 or ch<1):
|
|
||||||
print("Enter valid choice")
|
|
@ -1,107 +0,0 @@
|
|||||||
NoOfStudents = int(input("Enter number of students: "))
|
|
||||||
list1 = []
|
|
||||||
list2 = []
|
|
||||||
for i in range(0,NoOfStudents):
|
|
||||||
n = float(input("Enter student percentage: "))
|
|
||||||
list2.append(n)
|
|
||||||
for j in list2:
|
|
||||||
if(j != -1):
|
|
||||||
list1.append(j)
|
|
||||||
|
|
||||||
def avg():
|
|
||||||
sum1 = 0
|
|
||||||
for i in list1:
|
|
||||||
sum1 = sum1 + i
|
|
||||||
avg = sum1/NoOfStudents
|
|
||||||
print("Sum is: ",sum1)
|
|
||||||
print("Average is: ",avg)
|
|
||||||
|
|
||||||
def largest():
|
|
||||||
largest = None
|
|
||||||
for i in list1:
|
|
||||||
if(largest==None or largest<i):
|
|
||||||
largest = i
|
|
||||||
print("The highest marks is: ",largest)
|
|
||||||
|
|
||||||
def smallest():
|
|
||||||
smallest = None
|
|
||||||
for i in list1:
|
|
||||||
if(smallest==None or smallest>i):
|
|
||||||
smallest = i
|
|
||||||
print("The lowest marks is: ",smallest)
|
|
||||||
|
|
||||||
def frequency():
|
|
||||||
temp = 0
|
|
||||||
for i in list1:
|
|
||||||
max1 = 0
|
|
||||||
for j in range(0,len(list1)):
|
|
||||||
if(i == list1[j]):
|
|
||||||
max1 = max1 + 1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
if(max1>temp):
|
|
||||||
temp = max1
|
|
||||||
k = i
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
print("Marks with highest frequency is: ",k)
|
|
||||||
print("Frequency of the number is: ",temp)
|
|
||||||
|
|
||||||
def BubbleSort():
|
|
||||||
temp = 0
|
|
||||||
for i in range(0,len(list1)-1):
|
|
||||||
for j in range(0,len(list1)-1):
|
|
||||||
if(list1[j] > list1[j+1]):
|
|
||||||
temp = list1[j]
|
|
||||||
list1[j] = list1[j+1]
|
|
||||||
list1[j+1] = temp
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
print("Sorted list is: ",list1)
|
|
||||||
def top5():
|
|
||||||
list2 = list1[::-1]
|
|
||||||
for j in range(0,len(list2)):
|
|
||||||
print("Rank ",j+1," score is",list2[j])
|
|
||||||
|
|
||||||
def selection():
|
|
||||||
temp = 0
|
|
||||||
for i in range(0,len(list1)):
|
|
||||||
min1 = i
|
|
||||||
for j in range(i+1,len(list1)):
|
|
||||||
if(list1[min1]>list1[j]):
|
|
||||||
min1 = j
|
|
||||||
temp = list1[i]
|
|
||||||
list1[i] = list1[min1]
|
|
||||||
list1[min1] = temp
|
|
||||||
print(list1)
|
|
||||||
|
|
||||||
flag = 1
|
|
||||||
while flag == 1:
|
|
||||||
print("\nThe options are: ")
|
|
||||||
print("1. Total and average marks are: ")
|
|
||||||
print("2. Highest marks among the students: ")
|
|
||||||
print("3. Lowest marks among the students: ")
|
|
||||||
print("4. Marks with highest frequency is: ")
|
|
||||||
print("5. Top ",len(list1)," scores using bubble sort")
|
|
||||||
print("6. Top ",len(list1)," scores using selection sort")
|
|
||||||
print("7. Top ",len(list1)," scores are: ")
|
|
||||||
print("8. Exit")
|
|
||||||
ch = int(input("Enter choice: "))
|
|
||||||
if(ch == 1):
|
|
||||||
avg()
|
|
||||||
elif(ch == 2):
|
|
||||||
largest()
|
|
||||||
elif(ch == 3):
|
|
||||||
smallest()
|
|
||||||
elif(ch == 4):
|
|
||||||
frequency()
|
|
||||||
elif(ch == 5):
|
|
||||||
BubbleSort()
|
|
||||||
elif(ch == 6):
|
|
||||||
selection()
|
|
||||||
elif(ch == 7):
|
|
||||||
top5()
|
|
||||||
elif(ch == 8):
|
|
||||||
flag = 0
|
|
||||||
elif(ch>8 or ch<1):
|
|
||||||
print("Enter valid choice")
|
|
Loading…
Reference in New Issue
Block a user