0

Help a brother out please...

Does anyone have an answer to the code project under the "Exceptions and Files" module in the Python Core lesson? I've tried it very many times and I still can't get it. The question has really frustrated me and I have given up. It would really be helpful if someone can give me an answer on it. (A hint will still be very much appreciated too)

4th Jun 2021, 1:05 PM
Sidney Anya
7 Answers
+ 5
Show your attempt please.
4th Jun 2021, 1:06 PM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
4th Jun 2021, 2:12 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 1
The showing of attempt will be more appreciated
4th Jun 2021, 1:45 PM
Eashan Morajkar
Eashan Morajkar - avatar
0
For my attempt, this was the closest I could get out of all my other attempts: file = open("/usercode/files/books.txt", "r") for line in file: print(file.read(1)) print(len(line)) file.close()
4th Jun 2021, 3:41 PM
Sidney Anya
0
Sidney Anya what is the question? the first mistake is the for loop because you are iterating over an unreadable object
4th Jun 2021, 3:52 PM
Eashan Morajkar
Eashan Morajkar - avatar
0
This is the question: 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
8th Jun 2021, 12:35 PM
Sidney Anya
0
It took me a while but I've been able to get it. Here is my code: https://code.sololearn.com/c9N3YNZDJZdp
19th Sep 2021, 1:20 PM
Sidney Anya