DSL 1-3
DSL 1-3
Cricket = []
Badminton = []
Football = []
s=int(input("Enter no. of students : "))
c=int(input("Enter no. of students playing cricket : "))
for i in range (c):
cri =int(input("Enter roll no. of students playing Cricket : "))
Cricket.append(cri)
print("Students who play Cricket are : ",Cricket)
b=int(input("Enter no. of students playing badminton : "))
for i in range(b):
bd =int(input("Enter roll no. of students playing Badminton : "))
Badminton.append(bd)
print("Students who play Badminton are : ",Badminton)
f=int(input("Enter no. of students playing football : "))
for i in range(f):
fot =int(input("Enter roll no. of students playing Football : "))
Football.append(fot)
print("Students who play Football are : ",Football)
def cb(l1,l2):
a=[]
for i in l1:
if i in l2:
a.append(i)
return a
print("List of students who play both cricket and badminton : ", cb(Cricket,Badminton))
def union(l1, l2):
a = []
for i in l1:
if i not in l2:
a.append(i)
for i in l2:
if i not in l1:
a.append(i)
return a
print("List of students who play either cricket or badminton but not both : ",
union(Cricket, Badminton))
def football(l1,l2,l3):
a = []
for i in l3:
if i not in l1 and l2:
a.append(i)
return a
print("List of students who play neither cricket nor badminton : ",
football(Cricket,Badminton,Football))
def four(l1,l2,l3):
a=[]
for i in l1 + l3:
if i not in l2:
if i not in a:
a.append(i)
return a
print("List of students of play cricket and football but not badminton : ",
four(Cricket,Badminton,Football))
Output –
Enter no. of students : 8
Enter no. of students playing cricket : 3
Enter roll no. of students playing Cricket : 20
Enter roll no. of students playing Cricket : 23
Enter roll no. of students playing Cricket : 26
Students who play Cricket are : [20, 23, 26]
Enter no. of students playing badminton : 3
Enter roll no. of students playing Badminton : 20
Enter roll no. of students playing Badminton : 6
Enter roll no. of students playing Badminton : 5
Students who play Badminton are : [20, 6, 5]
Enter no. of students playing football : 3
Enter roll no. of students playing Football : 20
Enter roll no. of students playing Football : 21
Enter roll no. of students playing Football : 2
Students who play Football are : [20, 21, 2]
List of students who play both cricket and badminton : [20]
List of students who play either cricket or badminton but not both : [23, 26, 6, 5]
List of students who play neither cricket nor badminton : [21, 2]
List of students of play cricket and football but not badminton : [23, 26, 21, 2]
Source Code -
marklist=[]
n=int(input("Enter number of students : "))
print("Enter 0 marks if absent")
for i in range (n):
marks = int(input("Enter Marks : "))
marklist.append(marks)
#Average
total = 0
for marks in marklist:
total += marks
print("Average score = ", total/n)
#Max&Min
max=0
min=100
for marks in marklist:
if marks > max:
max = marks
if min > marks and marks !=0:
min = marks
print("Highest Score : ", max)
print("Lowest Score : ", min)
#Absent
absent = 0
for marks in marklist:
if marks == 0:
absent += 1
print("Number of Absent Students : ", absent)
def maxFrequency(marklist):
i=0
Max=0
for j in marklist:
if (marklist.index(j)==i):
if marklist.count(j)>Max:
Max=marklist.count(j)
mark=j
i=i+1
return(mark)
print("Score with highest frequency : ", maxFrequency(marklist))
Output-
Enter number of students : 4
Enter 0 marks if absent
Enter Marks : 9
Enter Marks : 8
Enter Marks : 0
Enter Marks : 10
Average score = 6.75
Highest Score : 10
Lowest Score : 8
Number of Absent Students : 1
Score with highest frequency : 9
Source Code –
row=int(input("Enter no. of rows for 1st matrix : "))
col=int(input("Enter no. of column for 1st matrix : "))
A=[]
for i in range (row):
a=[]
for j in range (col):
a.append(int(input(f"Enter element at ({i+1},{j+1}) : ")))
A.append(a)
print("Matrix 1 is : ")
for a in A:
print(a)
row2=int(input("Enter no. of rows for 2nd matrix : "))
col2=int(input("Enter no. of column for 2nd matrix : "))
B=[]
for i in range (row2):
b=[]
for j in range (col2):
b.append(int(input(f"Enter element at ({i+1},{j+1}) : ")))
B.append(b)
print("Matrix 2 is : ")
for b in B:
print(b)
#Addition
C=[]
for i in range (row):
c=[]
for j in range (col):
c.append(A[i][j]+B[i][j])
C.append(c)
print("Addition of the two matrices is : ")
for c in C:
print(c)
#Subtraction
D=[]
for i in range (row):
d=[]
for j in range (col):
d.append(A[i][j]-B[i][j])
D.append(d)
print("Subtraction of the two matrices is : ")
for d in D:
print(d)
#Multiplication
E=[[0]*col2 for _ in range(row)]
for i in range (row):
e=[]
for j in range (col2):
for k in range (col):
E[i][j]+=(A[i][k] * B[k][j])
print("Multiplication of the two matrices is : ")
for e in E:
print(e)
#Transpose1
F=[[0]*col for _ in range(row)]
for i in range (row):
f=[]
for j in range (col):
F[i][j]=A[j][i]
print("Transpose of matrix 1 is : ")
for f in F:
print(f)
#Transpose2
G=[[0]*col2 for _ in range(row2)]
for i in range (row2):
g=[]
for j in range (col2):
G[i][j]=B[j][i]
print("Transpose of matrix 2 is : ")
for g in G:
print(g)
Output –
Enter no. of rows for 1st matrix : 2
Enter no. of column for 1st matrix : 2
Enter element at (1,1) : 1
Enter element at (1,2) : 2
Enter element at (2,1) : 3
Enter element at (2,2) : 4
Matrix 1 is :
[1, 2]
[3, 4]
Enter no. of rows for 2nd matrix : 2
Enter no. of column for 2nd matrix : 2
Enter element at (1,1) : 5
Enter element at (1,2) : 6
Enter element at (2,1) : 7
Enter element at (2,2) : 8
Matrix 2 is :
[5, 6]
[7, 8]
Addition of the two matrices is :
[6, 8]
[10, 12]
Subtraction of the two matrices is :
[-4, -4]
[-4, -4]
Multiplication of the two matrices is :
[19, 22]
[43, 50]
Transpose of matrix 1 is :
[1, 3]
[2, 4]
Transpose of matrix 2 is :
[5, 7]
[6, 8]