[Solved] Python: Reading marks from a file then using marks to get class


import csv

# function to process data
def process_data(data):
    for item in data:
        marks = int(item[2])
        mclass="incorrect data entry try again"
        if marks == 0:
            mclass = "10.9"
        elif marks >= 0 and marks <= 100:
            mclass = "10.{}".format(10 - int(item[2][0]))
        yield '"{}","{}",{},{}'.format(item[0],item[1],item[2],mclass)

# read data to memory
data = []
with open("Maths_Mark.txt", "r") as csv_in:
    data = list(csv.reader(csv_in, delimiter=","))

# write contents to file
with open('Maths_Group.txt', 'w') as csv_out:
    for line in process_data(data):
        csv_out.write(line + "\n")

4

solved Python: Reading marks from a file then using marks to get class