#----------------------------------- # Word Wrap- This is a very simple # program meant to break up blocks # of text, automatically. Currently # it does not allow manual line breaks. #----------------------------------- # 1. Split the sentence by spaces # 2. Create empty string # 3. Initialize counting variable # 4. For each word... # a. If the length exceeds the # wraplength count, newline # b. Add the length of the word # to the counting variable # c. Add the word to the output # 5. Return the output #----------------------------------- def wrap(sentence, wraplength): words = (sentence.strip()).split(" ") output = "" chars = 0 for index in range(len(words)): if (len(words[index]) + chars) > wraplength: output += "\n" chars = 0 chars += len(words[index]) + 1 output += words[index] + " " return output #------------------# # Main Program # #------------------# amt = int(input("Input wrap amount: ")) print("For comparison,", amt, "characters is") for i in range(amt): print("=", end= "") print() while True: print(wrap(input("Input sentence: \n"), amt) + "\n")