+ 1
How do I get this code to print my results on different lines?
with open("/usercode/files/books.txt") as f: #your code goes here list =f.readlines() for i in range(len(list)): expression = list[i] num_words =str(len(expression.split())) line_number =str(i+1) print("Line",line_number,":",num_words,"words", end ="") I have also tried , as an alternative: results = ["Line",line_number,":",num_words,"words"] for result in results: print(results) Each print statement obtained in one big long line????
1 Respuesta
+ 4
The solution is simply to remove end="" from the print() function. That lets print use its default line ending, which is a newline.
print("Line",line_number,":",num_words,"words")