0

BOOK TITLES - python

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 https://code.sololearn.com/c2koI2c0h7SZ/?ref=app I have written the below code but it is showing error.

29th Oct 2020, 3:37 PM
JRANJAN BISWAL
JRANJAN BISWAL - avatar
5 Respostas
+ 1
A simpler way with 5 lines of code. A simple explanation, loop through all lines, and if a line has trailing/ending "\n" remove it from the count of the length. https://code.sololearn.com/cdaPdMWWeN3W/?ref=app
15th Dec 2020, 6:39 PM
Lam Wei Li
Lam Wei Li - avatar
0
It's working fine..
29th Oct 2020, 4:05 PM
Jayakrishna 🇮🇳
0
file = open("/usercode/files/books.txt", "r") #your code goes here books=file.readlines() for i in books: if i==books[-1]: value=len(i) else: value=len(i)-1 print(i[0]+str(value)) file.close()
25th Apr 2021, 10:29 AM
A Owadud Bhuiyan
A Owadud Bhuiyan - avatar
- 1
i fuck this sheet
24th Mar 2022, 12:26 PM
Angelina Budnik