#phython code to align line text=""" Langdon knew that he himself, like millions, was guilty of this. When it came to the circumstances of the world, denial had become a global pandemic. Langdon promised himself that he would never forget this. As the plane streaked west, Langdon thought of """ words = text.split() lines = [] current_line = [] word_count = 0 i = 0 while i < len(words): # CHAPTER + number detect karo if words[i] == "CHAPTER" and i + 1 < len(words) and words[i+1].isdigit(): # Pehle jo line chal rahi hai use save karo if current_line: lines.append(" ".join(current_line)) current_line = [] word_count = 0 lines.append("") lines.append("") lines.append("") # Chapter ko alag line me daalo lines.append(f"CHAPTER {words[i+1]}") lines.append("") i += 2 continue # Normal words (15 per line rule) current_line.append(words[i]) word_count += 1 if word_count == 15: lines.append(" ".join(current_line)) current_line = [] word_count = 0 i += 1 # Last line add karo if current_line: lines.append(" ".join(current_line)) final_text = "\n".join(lines) # Text file me save karo with open("linealign.txt", "w", encoding="utf-8") as f: f.write(final_text)