At the input lines are copied together by the column:

abcd ---------- efg ---------- 

It is impossible to print the length of each line, only the length of the first one is printed.

 for x in input().splitlines(): print(len(x)) 
  • Not sure, but it seems your example matched the markdown formatting. Put an example in the tag code or quote. править button - gil9red
  • I did not understand what you mean, I need to, without remembering the program, display the length of each line of characters copied to the console. Each line of characters is copied on a separate line. - Sergey Baranenkov
  • You have the following data in the question: abcd efg , but in the text of the question abcd----------efg---------- which of these is true? And about your problem, most likely when you insert text into input, the first line abcd\n falls into it, because it ends in \n . Why don't you take data for the program from a file? - gil9red
  • The correct text of the question :), is it possible to make the length of each line computed and printed? (I don’t know how to write it correctly, but all lines are copied 1 time in the input bar) - Sergey Baranenkov
  • one
    Ok, I corrected the question format. It seems to me that Input not very suitable for your task, I suggest pulling it out of the file. Show? - gil9red

2 answers 2

 import fileinput for line in fileinput.input(): print(len(line) - 1) # Длина вез знака '\n' 

To input lines, use the input() method of the inserted fileinput module.

The lines are read until the input ends with the end-of-file ( Ctrl + D ) sign.
When you want to finish the input by simply pressing the Enter key , add the code for the test for entering a string with a length of 1 (only the end of line character: \n ):

 import fileinput for line in fileinput.input(): if len(line) == 1: break print(len(line) - 1) 
  • there may not be a newline character at the end. You can len(line) - line.endswith('\n') - jfs

input is called and reads once (before the line break). If you call input in a loop, you get something similar. But better use sys.stdin