# Unit 6 Assignment.py - # # # # Uriel Campos 16 July 2022...

• 6

This preview shows page 1 - 3 out of 6 pages.

# Uriel Campos# 16 July 2022# Program below prints 4 tables and formats them all accordingly given# the data from courses.txt# start of opening and reading txt filecourses_file = open("courses.txt", "r")# start of table 1print("Table 1")print("")for course in courses_file.readlines():spaced_course_num = course[:5]for n in range(1):print(spaced_course_num[:2] + " " + spaced_course_num[2:])courses_file.close()# start of table 2print("")print("Table 2")print("")courses_file = open("courses.txt", "r")for course in courses_file.readlines():spaced_course_num = course[:5]course_name = course[5:]if course[-5].isdigit():course_num = course_name[:-5] + " " + course[-5:-1]elif course[-4].isdigit():course_num = course_name[:-4] + " " + course[-4:-1]elif course[-3].isdigit():course_num = course_name[:-3] + " " + course[-3:-1]elif course[-2].isdigit():course_num = course_name[:-2] + " " + course[-2:-1]else:course_num = course_name[:-1] + " " + course[-1]for n in range(1):edited_list = spaced_course_num[:2] + " " + spaced_course_num[2:]print(edited_list + " " + course_num)courses_file.close()# start of table 3print("")print("Table 3")print("")
courses_file = open("courses.txt", "r")for course in courses_file.readlines():spaced_course_num = course[:5]course_name = course[5:]for i in range(1):if len(course_name) > 20:if course[-5].isdigit():print(spaced_course_num + " " +course_name[:20] + " " + course[-5:-1])elif course[-4].isdigit():print(spaced_course_num + " " +course_name[:20] + " " + course[-4:-1].rjust(4, " "))elif course[-3].isdigit():print(spaced_course_num + " " +course_name[:20] + " " + course[-3:-1].rjust(4, " "))elif course[-2].isdigit():print(spaced_course_num + "" +course_name[:20] + " " + course[-2:-1])else:print(spaced_course_num + " " +course_name[:20] + " " + course[-1].rjust(3, " "))if len(course_name) == 19:print(spaced_course_num + " " +course_name[:15] + " " + course[-4:-1].rjust(9, " "))elif len(course_name) == 17:print(spaced_course_num + " " +course_name[:14] + " " + course[-3:-1].rjust(10, " "))edited_list = spaced_course_num[:2] + " " + spaced_course_num[2:]# print(edited_list + " " + course_num)"""courses_file.close()# start of table 4print("")print("Table 4")print("")

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 6 pages?

Course Hero member to access this document

Term
Spring
Professor
CIGAS
Tags
len