<jupyter_start><jupyter_text>Assignment 1  Initial Setup---This sets up the code which reads the file and stores all the data each in its appropriate variable<jupyter_code># === Variables =========================================
code = ''
title = ''
fieldCount = 0
f = []
studentCount = 0
students = []

# === Functions =========================================
def sortDATA(filename):
    '''Gets & reads the .txt file provided in the input and sorts its data into its relevant variables'''
    global code, title, fieldCount, f, studentCount, students
    with open(filename, 'rt') as sub:
        for line in sub.readlines():
            line = line.replace('\n','').replace(' ','').split('|')
            for entry in line:
                if entry == '':
                    line.pop(line.index(entry))
                try:
                    line[line.index(entry)] = int(entry)
                except:
                    try:
                        line[line.index(entry)] = float(entry)
                    except:
                        pass
            if line[0] == 'Code':
                code = line[1]
            elif line[0] == 'Title':
                title = line[1]
            elif line[0] == 'FieldCount':
                fieldCount = line[1]
            elif line[0] == 'F':
                for i in range(1,4):
                    f.append(line[i])
            elif line[0] == 'StudentCount':
                studentCount = line[1]
            elif line[0] == 'S':
                line.pop(0)
                stuDetails = []
                marks = []
                for entry in line:
                    if type(entry) == float:
                        marks.append(entry)
                    else:
                        stuDetails.append(entry)
                stuDetails.append(marks)
                students.append(tuple(stuDetails))
        students = tuple(students)
        
def printAllDATA():
    '''Prints all the sorted Data for the subject loaded through the sortDATA() funtion.'''
    print(code)
    print(title)
    print(fieldCount)
    print(f)
    print(studentCount)
    print(students)
# Run the function
sortDATA('subject.txt')<jupyter_output><empty_output><jupyter_text>Assignment 1 (a)<jupyter_code>for student in students:
    print(student)### Assignment 1 (a)<jupyter_output>(18447565, 'VANDERGRAFF', 'T', [74.0, 42.5, 57.0])
(18907347, 'MARS', 'V', [80.5, 60.0, 72.0])
(18981993, 'FENNEL', 'WG', [77.5, 55.0, 69.0])
(18983070, 'ECHOLLS', 'L', [69.0, 40.0, 71.0])
(18930300, 'KANE', 'DS', [65.0, 47.5, 80.0])
(18915430, 'KANE', 'L', [0.0, 0.0, 34.0])
(18917104, 'NAVARRO', 'EW', [58.0, 35.0, 66.5])
(18928929, 'CASABLANCAS', 'D', [50.5, 57.5, 64.0])
(18982917, 'CASABLANCAS', 'C', [88.5, 62.5, 87.5])
(18971724, 'COOK', 'J', [61.0, 37.5, 63.5])
(18982863, 'MANNING', 'M', [51.5, 52.5, 79.0])
(18928875, 'GANT', 'C', [66.5, 32.5, 43.0])
(18927829, 'HAMILTON', 'Y', [69.0, 35.0, 48.0])
(18963759, 'TOOMBS', 'F', [83.0, 60.0, 74.0])
(18917386, 'DAMATO', 'L', [56.5, 70.0, 73.0])
(18961542, 'LAMB', 'D', [87.0, 42.5, 74.0])
(18130217, 'WEIDMAN', 'C', [25.0, 57.5, 86.0])
(18966580, 'CLEMMONS', 'V', [46.5, 32.5, 77.5])
(18934516, 'VANLOWE', 'V', [71.0, 17.5, 74.5])
(18933190, 'MCCORMACK', 'C', [71.5, 77.5, 70.5])
(18930122, 'POMEROY', 'S', [57.0, 57.5, 78.0])
(18940511, 'SINCL[...]<jupyter_text>Assignment 1 (b)<jupyter_code>with open('finalmarks.txt', 'wt') as fMark:
    fMark.write('') # Makes sure the 'finalmarks.txt' file is empty on each run of the script (won't replicate data)
    
for student in students:
    name = student[1]+" "+student[2]
    finMark = round(student[3][0]*(f[0]/100)) + round(student[3][1]*(f[1]/100)) + round(student[3][2]*(f[2]/100))
    with open('finalmarks.txt', 'at') as fMark:
        fMark.write(name+" "+str(finMark)+'\n')<jupyter_output><empty_output><jupyter_text>Assignment 1 (c)<jupyter_code>assignment1 = []
assignment2 = []
final = []

def avg(num):
    sumOfNumbers = 0
    for t in num:
        sumOfNumbers = sumOfNumbers + t

    avg = sumOfNumbers / len(num)
    return round(avg, 2)

for student in students:
    assignment1.append(student[3][0])
    assignment2.append(student[3][1])
    final.append(student[3][2])
    
print('| Assignment 1 |', str(min(assignment1)), " |", str(max(assignment1)), "|", str(avg(assignment1)), "|")
print('| Assignment 2 |', str(min(assignment2)), " |", str(max(assignment2)), "|", str(avg(assignment2)), "|")
print('| Final        |', str(min(final)), "|", str(max(final)), "|", str(avg(final)), "|")<jupyter_output>| Assignment 1 | 0.0  | 89.5 | 63.52 |
| Assignment 2 | 0.0  | 77.5 | 46.92 |
| Final        | 34.0 | 87.5 | 68.04 |
{'fraction_non_alphanumeric': 0.2059012187299551, 'fraction_numerical': 0.09685695958948044, 'mean_word_length': 2.5929339477726576, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '59555', 'license': 'MIT', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1717, 'n_words': 396, 'path': '2020_12_05_Assignment/Assignment_1_Solution/Assignment 1.ipynb', 'repo_name': 'MePerplexeus/AI-Practice-Assignments', 'size': '4677'}