Grpa Week 4 Solutions
Grpa Week 4 Solutions
Grpa Week 4 Solutions
PROGRAM 1:
SOLUTION 1:
sentence = input()
word = input()
l = sentence.split()
if (word not in l):
print('NO')
else:
count = 0
while(word in l):
count +=1
l.remove(word)
print('YES')
print(count)
PROGRAM 2:
You are given a list marks that has the marks scored by a class of students in a
Mathematics test. Find the median marks and store it in a float variable named
median. You can assume that marks is a list of float values
SOLUTION 2:
def solution(marks):
temp=0
for i in range(0, len(marks)):
for j in range(i+1, len(marks)):
if(marks[i] > marks[j]):
temp = marks[i];
marks[i] = marks[j];
marks[j] = temp;
if(len(marks)%2==0):
center=marks[int((len(marks)/2)-1)]
center1= marks[int((len(marks)/2))]
median=(center+center1)/2
else:
median=marks[len(marks)/2]
### Enter your solution above this line
return median
PROGRAM 3:
Accept two square matrices AA and BB of dimensions n \times nn×n as input and
compute their product ABAB.
SOLUTION 3:
n = int(input())
A = []
B = []
for i in range(n):
row=input()
row = row.split(",")
A.append(row)
for i in range(n):
row = input()
row = row.split(",")
B.append(row)
for k in range(n):
for i in range(n):
sum = 0
for j in range(n):
sum += (int(A[k][j])*int(B[j][i]))
if(i < n-1):
print(sum,end="")
print(",",end="")
else:
print(sum)
PROGRAM 4:
You are given the names and dates of birth of a group of people. Find all pairs of
members who share a common date of birth. Note that this date need not be common
across all pairs. It is sufficient if both members in a pair have the same date of
birth.
SOLUTION 4:
names = input().split(',')
bdays = input().split(',')
n = len(names)
for i in range(n):
bdays[i] = int(bdays[i])
common = [ ]
for i in range(n):
for j in range(n):
if ((i != j) and
(bdays[i] == bdays[j]) and
names[i] < names[j]):
pair = [names[i], names[j]]
common.append(pair)
PROGRAM 5:
,y
i
), 1\leq i \leq n1≤i≤n, in the 2-D plane as input. Also, you are given a point PP
with coordinates (x,y)(x,y). Print all points in the sequence that are nearest to
PP. If multiple points have the same least distance from PP, print the points in
the order of their appearance in the sequence.
SOLUTION 5:
n = int(input())
L = [ ]
# Append all points in the sequence to the list L
for i in range(n):
L.append(input())
# Point P
point = input().split(',')
x = int(point[0])
y = int(point[1])