Question: i have this code that reads from a file - the file finds the values under Course No. and prints them import sys def find_courses(filename):
i have this code that reads from a file - the file finds the values under "Course No." and prints them
import sys
def find_courses(filename):
course_num = []
course_section = []
with open(filename, 'r', encoding='latin-1') as file:
for line in file:
cols = line.split()
if len(cols) > 1 and cols[0].isalnum() and len(cols[0]) >= 5:
if len(cols[0]) >= 1 and cols[0][:11].isalnum():
course_num.append(cols[0])
section = cols[1]
if section.isdigit():
course_section.append(section)
all_courses = len(course_num)
all_course_sections = len(course_section)
print(f'{all_courses} {sorted(set(course_num))}')
print(f'{all_course_sections} {course_section}')
if __name__ == "__main__":
filename = sys.argv[1]
find_courses("/work/FA-2020-DAY.txt")
this is a sample of the file- Course No. Sec Course Title Hrs Faculty Mtg Time Days Bld Room Cap Max Reg ACTIVE TECHNOLOGIES ***PREREQ:CSC160
for some reason, the code prints "Active" however, "Active" is not a value under "Course No." Knowing that "Course No." is at index 0 but "Active" is not at index 0. how to fix the problem and prevent it from printing Active?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
