can any one solve | Sololearn: Learn to code for FREE!


can any one solve

Book Titles You have been asked to make a special book categorization program, which assigns each book a special code based on its title. The code is equal to the first letter of the book, followed by the number of characters in the title. For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space). You are provided a books.txt file, which includes the book titles, each one written on a separate line. Read the title one by one and output the code for each book on a separate line. For example, if the books.txt file contains: Some book Another book Your program should output: S9 A12

3/29/2021 11:19:54 AM


4 Answers

New Answer


Please post your attempt here too...


Post your attempt


Seems to be your homework. Anyways post what you have tried so far


#I find very difficult to solve but #finally solved it file = open("/usercode/files/books.txt", "r") for i in file.readlines(): print(i[0]+str(len(i.strip('\n')))) #your code goes here file.close() read the question properly they asked to to use file. readline() they asked to print first character only so I used i[0] and strip function here is used to remove /n here