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)) 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)) 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) len(line) - line.endswith('\n') - jfsinput 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
Source: https://ru.stackoverflow.com/questions/846884/
All Articles
правитьbutton - gil9redabcd efg, but in the text of the questionabcd----------efg----------which of these is true? And about your problem, most likely when you insert text into input, the first lineabcd\nfalls into it, because it ends in\n. Why don't you take data for the program from a file? - gil9redInputnot very suitable for your task, I suggest pulling it out of the file. Show? - gil9red