7.13 LAB: Catalog Publisher When a publisher prepares a document to be published, the text of the document is formatted laying out the content across pages and within limitations of the page width. Such a process involves spitting the text in a manner that text is wrapped over many lines. Consider the task of laying out course information in a university's course catalog. Each course has a title, a list of prerequisites, and a description all of which are printed using word wrap. For example, for the content:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

using (python3)

7.13 LAB: Catalog Publisher
When a publisher prepares a document to be published, the text of the document is formatted laying out the content across pages and
within limitations of the page width. Such a process involves spitting the text in a manner that text is wrapped over many lines. Consider the
task of laying out course information in a university's course catalog. Each course has a title, a list of prerequisites, and a description all of
which are printed using word wrap. For example, for the content:
cosc 380 seminar on the Computer Profession and Ethics
Prerequisite: Instructor permission
Reading, review, and discussion of the current literature of computer science and industry trade
journals; effective oral presentations; employment prospects. Topics on computer ethics and review
of case studies on computer ethics from professional journals with discussion of the issues
involved. Should be taken the semester before an internship or the first semester of the senior
year. Should not be taken at the same time as cosc 480.
The publisher may wish to print the content with a limit of 50 characters per line, in which case the text would be formatted as:
cosc 380 Seminar on the Computer Profession and
Ethics
Prerequisite: Instructor permission
Reading, review, and discussion of the current
literature of computer science and industry trade
journals; effective oral presentations; employment
prospects. Topics on computer ethics and review of
case studies on computer ethics from professional
journals with discussion of the issues involved.
Should be taken the semester before an internship
or the first semester of the senior year. Should
Transcribed Image Text:7.13 LAB: Catalog Publisher When a publisher prepares a document to be published, the text of the document is formatted laying out the content across pages and within limitations of the page width. Such a process involves spitting the text in a manner that text is wrapped over many lines. Consider the task of laying out course information in a university's course catalog. Each course has a title, a list of prerequisites, and a description all of which are printed using word wrap. For example, for the content: cosc 380 seminar on the Computer Profession and Ethics Prerequisite: Instructor permission Reading, review, and discussion of the current literature of computer science and industry trade journals; effective oral presentations; employment prospects. Topics on computer ethics and review of case studies on computer ethics from professional journals with discussion of the issues involved. Should be taken the semester before an internship or the first semester of the senior year. Should not be taken at the same time as cosc 480. The publisher may wish to print the content with a limit of 50 characters per line, in which case the text would be formatted as: cosc 380 Seminar on the Computer Profession and Ethics Prerequisite: Instructor permission Reading, review, and discussion of the current literature of computer science and industry trade journals; effective oral presentations; employment prospects. Topics on computer ethics and review of case studies on computer ethics from professional journals with discussion of the issues involved. Should be taken the semester before an internship or the first semester of the senior year. Should
or the first semester of the senior year. Should
not be taken at the same time as CosC 480.
Write a program that will input a line width and then a list of course names until a 'q' is entered to terminate the program. For each course
name, read the course information from a file (using the function load_course provided in the default template) and print the content of the
course information using word wrap according to the user's specified line width. If the course information could not be loaded print "Unable
to load course information for course" followed by the course name.
A blank line is to be printed after printing the content of a course.
The function load_course(course_name) provided in the default templates will attempt to read from the file system a file by the name of
course with the extension ".txt". Content for courses is thus in loaded from files each of which has three lines. The first line is the title, the
second is the prerequisites, and the third the course description. The prerequisites could be blank indicating there are no prerequisites.
Function load_course returns this information is a list of strings. If load_course is unable to read a file by the given name, it will return None.
To get started, the default template provides the initial declaration for a function word_wrap_text which is passed a paragraph of text to be
word-wrapped and a width. The paragraph is a long line of text without any new lines characters. The function is to return a string with
newlines inserted accordingly so that each line contains as many words as possible provided the length of a line does not exceed the width.
The program must complete and use the word_wrap_text function.
Let's look at a suggested strategy to complete the function word_wrap_text. Define a line variable to be an empty string and lines variable to
be an empty list. Use the string split method to split the paragraph into a series of words. A for each loop can then be used to loop over the
words one word at a time. If the line variable is not empty and length of line plus length of the word plus one (to account for a space
between words) is less than the width, concatenated a space and the word to the end of the line. Otherwise, append the line to the lines list
and set the line to be just the word. After the loop append the line to the lines list provided it is not empty. Finally, use the join method of a
string "\n" to join the lines together separated by newlines and return the result.
A final enhancement to the word_wrap_text is to handle the case where words (being some sequences of non-whitespace characters)
exceed the given with. In this event, the word is substringed as needed into where each substring is of length width.
Transcribed Image Text:or the first semester of the senior year. Should not be taken at the same time as CosC 480. Write a program that will input a line width and then a list of course names until a 'q' is entered to terminate the program. For each course name, read the course information from a file (using the function load_course provided in the default template) and print the content of the course information using word wrap according to the user's specified line width. If the course information could not be loaded print "Unable to load course information for course" followed by the course name. A blank line is to be printed after printing the content of a course. The function load_course(course_name) provided in the default templates will attempt to read from the file system a file by the name of course with the extension ".txt". Content for courses is thus in loaded from files each of which has three lines. The first line is the title, the second is the prerequisites, and the third the course description. The prerequisites could be blank indicating there are no prerequisites. Function load_course returns this information is a list of strings. If load_course is unable to read a file by the given name, it will return None. To get started, the default template provides the initial declaration for a function word_wrap_text which is passed a paragraph of text to be word-wrapped and a width. The paragraph is a long line of text without any new lines characters. The function is to return a string with newlines inserted accordingly so that each line contains as many words as possible provided the length of a line does not exceed the width. The program must complete and use the word_wrap_text function. Let's look at a suggested strategy to complete the function word_wrap_text. Define a line variable to be an empty string and lines variable to be an empty list. Use the string split method to split the paragraph into a series of words. A for each loop can then be used to loop over the words one word at a time. If the line variable is not empty and length of line plus length of the word plus one (to account for a space between words) is less than the width, concatenated a space and the word to the end of the line. Otherwise, append the line to the lines list and set the line to be just the word. After the loop append the line to the lines list provided it is not empty. Finally, use the join method of a string "\n" to join the lines together separated by newlines and return the result. A final enhancement to the word_wrap_text is to handle the case where words (being some sequences of non-whitespace characters) exceed the given with. In this event, the word is substringed as needed into where each substring is of length width.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Troubleshooting
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education