0
Please help cause i dont understand how to complete this
Ok so im in the project call "Book titles" from python 3,and i dont know how to erase the ("\n") from the words. The output should be: H12 T16 P19 G18 and mine is: H13 T17 P120 G18 this is my code: file = open("/usercode/files/books.txt", "r") line=file.readlines() for line in line: print(line[0]+str(len(line))) file.close()
4 Antworten
+ 3
Check if line is ending with "\n",
If line[-1]=="\n", if yes then use rstrip() method to remove newline character like line=line.rstrip()
rstrip() removes from the end of string, and there are strip() and lstrip() as well.
+ 3
Using rstrip method with "\n" as param:
for line in line:
line = line.rstrip("\n")
print(......)
+ 2
OOOOHHHH IT WORKS THANK YOU BOTH VERY VERY MUCH
+ 1
Ohhh thank u very much both