Reading a text | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Reading a text

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 How can one do this

5th Dec 2020, 6:27 PM
Ajewumi Emmanuel Ayomide
Ajewumi Emmanuel Ayomide - avatar
3 Answers
+ 3
Ajewumi Emmanuel Ayomide , for example you can first remove the newline character "\n" after each line (it's mentioned that readlines function consumes the newline character). Next form a string where each title is a combination of the first letter and the title length. Print the result.
5th Dec 2020, 7:01 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Ajewumi Emmanuel Ayomide , take the first letter of the title and the length of that title forming a new string.
5th Dec 2020, 7:14 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
the "next" is the one I don't know how to doTheWh¡teCat 🇧🇬
5th Dec 2020, 7:04 PM
Ajewumi Emmanuel Ayomide
Ajewumi Emmanuel Ayomide - avatar