0

Python exercise from Sololearn

Dear all! I am requested to open a file that contains titles of books (1 in each row). I am then asked to print the first letter of the title plus the number of characters in it. For instance, The Great Gatsby gives as a result T16. Clearly, for all the titles but the last one I should not count the '\n' character. Did anybody find a solution? :) EDIT: file = open("mybooks", "r") Titles = file.read().split('\n') for title in Titles: print(title[0]+str(len(title)))

26th Jun 2021, 1:07 PM
Stefano Morelli
Stefano Morelli - avatar
3 Antworten
+ 3
titles = file.read().split("\n") # so titles is an array of lines without ending "\n"...
26th Jun 2021, 1:17 PM
visph
visph - avatar
+ 2
Yes. So Many... edit: pls dont ask solution.. if you want , pls try it yourself first and post your try if unsolved. someone help you to correct it...
26th Jun 2021, 1:12 PM
Jayakrishna 🇮🇳
0
.strip('\n')
26th Jun 2021, 1:13 PM
Slick
Slick - avatar