113k views
0 votes
Write a function, printResult(), with two parameters (englishStudent, mathStudent). Both of the parameters are list of student IDs. englishStudent is the list of English students, mathStudent is the list of Math students.

The function will return the list of students who are only taking Math class. (python)

User David Xia
by
8.7k points

1 Answer

6 votes

Answer:

def printStudent(englishStudent, mathStudent):

onlyMath = mathStudent

for m in mathStudent:

if m in englishStudent:

i = onlyMath.index(m)

onlyMath.pop(i)

print(onlyMath)

# just an example:

printStudent([1193, 4356, 4572, 1035], [3954, 1035, 8548, 1193])

Step-by-step explanation:

I made onlyMath as a copy of mathStudent. Then, with a for loop, the algorithm checks every ID in it and removes the ones that are also in englishStudent, leaving only the math students.

User Thomas Altmann
by
7.7k points

No related questions found