Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to rewrite this program so that it reads strings from a . txt file and builds the list courses instead of defining all
I need to rewrite this program so that it reads strings from a txt file and builds the list courses instead of defining all the data as part of your program itself. The text file is called courses.txtThe file aspect should be the only thing that you change the rest of the program logic should remain the same.
#table
def tablecourses:
printTable
total
for course in courses:
data course.split
length lendata
printdata data
total intdatalength
print
total: total
#table
def tablecourses:
printTable
for course in courses:
deptcode course:
courseinfo course:
printfdeptcodecourseinfo
def tablecourses:
printTable
totalenrollment
for course in courses:
data course.split
deptcode data
coursenum data
enrollment intdata
title joindata:
# Truncate title to a max length, eg characters
maxtitlelength
if lentitle maxtitlelength:
title title:maxtitlelength
printfdeptcodecoursenumtitleljustmaxtitlelengthenrollment:d
totalenrollment enrollment
printTotal enrollment:", totalenrollment
def tablecourses:
printTable
# Find the length of the longest title
maxtitlelength maxlenjoincoursesplit: for course in courses
# Sort courses by title
coursessorted sortedcourses keylambda x: joinxsplit:
totalenrollment
for course in coursessorted:
data course.split
deptcode data
coursenum data
enrollment intdata
title joindata:
printfdeptcodecoursenumtitleljustmaxtitlelengthenrollment:d
totalenrollment enrollment
printTotal enrollment:", totalenrollment
def main:
courses
courses CS Introduction to Python Programming
CS Operating Systems Adminstration
CS Computer Networking
CS Discrete Mathmatics
CS Computer Architecture
MA Calculus and Analytical Geometry for Majors I
MA Linear Algebra
MA Precalculus Mathmatics
CS Introduction to Cybersecurity
IS Data Management Systems
MG Advanced Business Statistics
courses.appendIT Information Technology
courses.appendCS Cybersecurity Administration
courses.appendCS Developing the User Experience
tablecourses
tablecourses
tablecourses
tablecourses
#calling main function
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started