Help me to solve s problem on python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help me to solve s problem on python

You need to create a special categorization program that will assign a special code to each book depending on its title: The code is the first letter of the book title and the number of characters in the title. For example, the code for the book "Harry Potter" would look like this: H12, since the title consists of 12 characters (including spaces) You are given a books.txt file, the titles of the books are indicated on separate lines. You need to read the headings one by one and write the code for each book on separate lines. For example, if a books.txt file contains headers like this: Some kind of book Another book Your program should return the result: K14 D12

14th Oct 2020, 5:33 PM
Rostik
6 Answers
+ 10
Rostik , sorry to say, but this it not an attempt. There are some lines of code missing. Please take some time and try to do your best. Then post it again. Thanks!
14th Oct 2020, 5:46 PM
Lothar
Lothar - avatar
+ 3
This code shows all to read and write text files inclusive solution for your problem: https://code.sololearn.com/cPeBWF4tkD8w/?ref=app
14th Oct 2020, 8:31 PM
JaScript
JaScript - avatar
+ 2
attemp: file = open("/usercode/files/books.txt", "r") file.close()
14th Oct 2020, 5:34 PM
Rostik
+ 2
Rostik You wrote "The code is the first letter of the book title and the number of the characters in the title." Then how come "Some kind of book" gets K14 as a code. The same thing with "Another book" with D12. Am I not getting it right, or was that a typo? cause even the rule of "first letter of book title" isn't employed in those two examples 🤔
15th Oct 2020, 1:13 AM
Ipang
+ 2
JaScript this code is error
16th Oct 2020, 6:43 AM
SammE
SammE - avatar
+ 1
Rostislav Khalilov Зачем? Я сдал это задание в курсе Питона.
16th Oct 2020, 7:13 AM
JaScript
JaScript - avatar