0

Please i need help with this python problem. I've been stuck on it for days.

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 Code should look something like this: file=open("/usercode/files/books.txt", "r") #your code goes here file.close()

26th May 2021, 3:25 AM
Promise Ezenwanne
Promise Ezenwanne - avatar
9 odpowiedzi
0
#context manager with open("usercode/files/books.txt",'r') as file: names=[i[:-1] for i in file.readlines() if not i=="\n"] for i in names: print(f"{i[0].capitalize()}{len(i)}")
27th May 2021, 10:01 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 7
⬜⬜⬜⬜⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬛⬜⬛⬜⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬜⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬛⬜⬛⬛⬜ ⬜⬛⬜⬛⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬜⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬜⬜⬜⬛⬜ ⬜⬛⬛⬛⬛⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬛⬜⬜⬜⬜⬜ ⬜⬜⬜⬜⬜⬜⬜ ⬜⬛⬛⬛⬛⬛⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬛⬜⬜⬜ ⬜⬜⬜⬜⬜⬜⬜ IS REQUIRED
26th May 2021, 3:34 AM
NEZ
NEZ - avatar
+ 4
Can we get your try first ?
26th May 2021, 3:28 AM
Ayush Kumar
Ayush Kumar - avatar
+ 4
1.Firstly you have to split file by new line and create a list . 2.you have to measure length of each line .and get the first letter of line . 3.then just add them in print statement . Just try make some errors and solve it.
26th May 2021, 5:13 AM
Yash Wable 🇮🇳
Yash Wable 🇮🇳 - avatar
+ 1
If that's your attempt go through the lessons again and if you don't understand them use Google to find more information.
26th May 2021, 4:25 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Also check on my profile i am sure i've solved a problem like that one. Dont forget to like and follow 🤣😉
26th May 2021, 9:12 PM
Henry Mwandama
Henry Mwandama - avatar
27th May 2021, 1:17 PM
RuntimeERROR
RuntimeERROR - avatar
0
Here is my attempt; file = open("/usercode/files/books.txt", "r") #your code goes here print (file.read()) file.close() But the output I get is Harry Potter The Hunger Games Pride and Prejudice Gone with the Wind Instead of H12 T16 P19 G18 I'm a beginner
26th May 2021, 3:41 AM
Promise Ezenwanne
Promise Ezenwanne - avatar
0
I've finally been able to figure this out and it took me quite a while to learn. Plus I had to go practice Python some more. Here is what I got: https://code.sololearn.com/c9N3YNZDJZdp
19th Sep 2021, 1:14 PM
Sidney Anya