Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got Table 1 & 2 done, but once i add in table 3 it prints multiple times and I ' m not sure why?

I got Table 1 & 2 done, but once i add in table 3 it prints multiple times and I'm not sure why?
For Table3, truncate the titles to the number of characters shown, but watch out for short titles. Make sure the enrollments all line up as shown. Add up all the enrollments and print the total.
For Table 4, sort the list (this is one statement in Python), and print the complete title, but make sure all the enrollments line up as shown. For Table 4, make sure your program actually prints the table based on the length of the longest title. You will have to write code to find the length of the longest title, then use that number.
#table 1
def table1(courses):
print("Table 1")
total =0
for course in courses:
data = course.split()
deptcode = data[0].strip()
coursenum = data[1].strip()
enrollement = data[len(data)-1].strip()
length = len(data)
print(data[0]+""+ data[1])
total += int(data[length-1])
print("
total: ", total)
#table2
def table2(courses):
print("Table 2")
for course in courses:
dept_code = course[:2]
course_info = course[2:]
print(f"{dept_code}{course_info}")
#table3
def table3(courses):
print("Table 3")
item ={}
k =0
for course in courses:
data = course.split()
nm =("".join(data[2:len(data)-1])).strip()
item[k]= len(nm)
k +=1
sorted_x = sorted(item.items(), key = lambda kv: kv[1], reverse = True)
for i in sorted_x:
print(courses[i[0]])
def main():
courses =[]
courses =['CS 152 Introduction to Python Programming 21',
'CS 369 Operating Systems Adminstration 8',
'CS 365 Computer Networking 19',
'CS 208 Discrete Mathmatics 124',
'CS 319 Computer Architecture 14',
'MA 221 Calculus and Analytical Geometry for Majors I 12',
'MA 311 Linear Algebra 7',
'MA 150 Precalculus Mathmatics 27',
'CS 335 Introduction to Cybersecurity 20',
'IS 361 Data Management Systems 22',
'MG 315 Advanced Business Statistics 6']
courses.append('IT 745 Information Technology 78')
for aCourse in courses:
print(aCourse)
table1(courses)
table2(courses)
table3(courses)
#calling main function
main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago