+ 2
Book title q
Hi, my code and output is shown below file = open("/usercode/files/books.txt", "r") #your code goes here lines = file.readlines() for line in lines: print(line[0]+str(len(line))) file.close() Your Output H13 T17 P20 G18 I think the print() function causes the newline ending problem. I’ve considered using end=“” and it gets rid of the newlines I do want. I do not know what resolvers there are without my code looking a little bit hacky. I’m interested in a clean way to get my code to work
5 Antworten
+ 3
Geoffrey Bolton yes
+ 2
I see. So, the problem wasnt with the newline ending. It was that I was overcounting the length due to there being a newline character at the end of a line
+ 2
Check my code:
https://code.sololearn.com/cF5af5g1067W/?ref=app
+ 1
You can use repr instead of print to see what the line contains.