+ 1

Why can't I print the first letters correctly?

file = open("/usercode/files/books.txt", "r") elements = file.readlines() con_elements = len(elements) i = 0 while i < con_elements: word = elements[i] if "\n" in word: a = len(elements[i]) - 1 else: a = len(elements[i]) letters = word[i] con_word = str(a) i = i + 1 print(letters + con_word) file.close() https://code.sololearn.com/cdnBIi34989r/?ref=app

6th Mar 2022, 6:55 PM
Paulo
Paulo - avatar
1 Respuesta
+ 3
You need letters = word[0] Instead of letters = word[i]
6th Mar 2022, 7:21 PM
Jayakrishna 🇮🇳