...

/

Solution Review: Extracting all the Students With Marks

Solution Review: Extracting all the Students With Marks

This review explains the solution for the "student names" problem

We'll cover the following...

Solution

Press + to interact
def student_names(filename):
mylist = []
with open(filename) as f:
for line in f:
k = line.split(' : ')
myval = []
for num in k[1].split():
num = int(num)
myval.append(num)
total = sum(myval)
if (total > 10):
mylist.append(k[0])
return mylist
filename = 'test.txt'
result = student_names(filename)
print(result)

Explanation

The first thing we need to do is read the text file using the open command. Observe this in line 4 of the above code. Next, at line 5, we can use a for loop to traverse over the contents of the text file.

Note: ...