Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is test code please use python to solve. Exercise 8: Justify any Text Complete the function consistent LineLength' taking two parameters, a fi name,

image text in transcribed

image text in transcribed

this is test code

image text in transcribed

please use python to solve.

Exercise 8: Justify any Text Complete the function consistent LineLength' taking two parameters, a fi name, and a maximum length (i.e., a strictly positive integer number). T function opens the file, reads every line, and returns a list of strings whe every string represents a line that is filled as much as possible without ceeding the given maximum length. Example: consider a file containing the following lines from 'Alic Adventures in Wonderland! Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it,"and what is the use of a book," thought Alice, "without pictures or conversations?" The corresponding output for length - 50 would be: ['Alice was beginning to get very tired of sitting', by her sister on the bank, and of having nothing', 'to do: once or twice she had peeped into the book', 6 'her sister was reading, but it had no pictures or', 'conversations in it, "and what is the use of a', 'book," thought Alice, "without pictures or', 'conversations?"'] You do not need to deal with multiple paragraphs of text. That is, you can group together words from different paragraphs. Finally, you can assume that no word is longer than the maximum length. def test_consistent_line_length(): script_dir = os. path.dirname (os.path.abspath(_file_)) input_file = Path(script_dir, "test_data", "text1.txt") assert consistentLineLength(input_file, 50) == [ "Alice was beginning to get very tired of sitting", "by her sister on the bank, and of having nothing", "to do: once or twice she had peeped into the book", "her sister was reading, but it had no pictures or", 'conversations in it, "and what is the use of a', 'book," thought Alice, "without pictures or', conversations?", ] assert consistentLineLength(input_file, 20) == [ "Alice was beginning", "to get very tired of", "sitting by her", "sister on the bank,", "and of having", "nothing to do: once", "or twice she had", "peeped into the book", "her sister was", "reading, but it had", "no pictures or", "conversations in", 'it, "and what is the', 'use of a book,"', "thought Alice,", ""without pictures or', 'conversations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions