+ 1
Can you rate my code for "book title" pls
Here is my code. It is working, but i feel it is not the best way for writing: file = open("/usercode/files/books.txt", "r") lines = file.readlines() l = len(lines) i = 0 while i < (l-1): print(str(lines[i])[0]+str(len(lines[i])-1)) i+=1 print(str(lines[i])[0]+str(len(lines[i]))) file.close()
1 Antwort
0
Overall its GOOD.
You can update this thing:
>> since you know the number of iteration then why use while loop instead of for loop
In case you wanna see my one,
file = open("/usercode/files/books.txt", "r")
x = file.read()
x = x.split("\n")
for i in x:
print(i[0]+str(len(i)))
file.close()