Question: If i have this data in a file 10:15 COURSE OF STUDY schddep For FA 2020 UG20 Catalog DAY Subprog Course No. Sec Course Title

If i have this data in a file

10:15 COURSE OF STUDY schddep For FA 2020 UG20 Catalog DAY Subprog

Course No. Sec Course Title Hrs Faculty Mtg Time Days Bld Room Cap Max Reg ABA145 01 INTRO AUTISM SPECTRUM DISORDER 3.00Rosenberg, TBA ------- ONLI 0 25 20

ABA280 01 INTRO TO BASIC PRINCIPLES OF ABA 3.00Radzilowic 8:00- 9:15AM --T-R-- WAX 239 24 12 7

ABA400 01 PRACTICUM IN AUTISM AND ABA I 12.00Davis, C. TBA ------- ONLI 0 12 1

And i want to access and extract the data under "Course No." - meaning I want to print "ABA145" "ABA280"

Using my code what should i change to make do that?

import sys

def class_count(filename):

classes = set() # using sets to avoid duplicate

class_sections = set()

#For some reason when I tested the SP files it wont work so I googled it and found

# this syntax encoding='latin-1'

with open(filename, encoding='latin-1') as file:

for line in file:

check_index_in_range = line.split()

if len(check_index_in_range) >= 2: # checks if the indices are in range

# class name is the first index in the file

class_name = check_index_in_range[0]

# section number is the second index in the file

section = check_index_in_range[1]

# add the class name to the set classes and avoud duplicates

classes.add(class_name)

# add the section to the set classs sections also to avoid duplicates

class_sections.add(section)

# using the function len to determine the number of classes

total_classes = len(classes)

total_class_sections = len(class_sections) # same thing but for sections

print("The total number of classes is:", total_classes)

print("The total number of class sections is:", total_class_sections)

if __name__ == "__main__":

filename = sys.argv[1]

class_count("/work/FA-2020-DAY.txt")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!