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)
7 odpowiedzi
+ 5
Show your attempt please.
+ 1
The showing of attempt will be more appreciated
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()
0
Sidney Anya what is the question? the first mistake is the for loop because you are iterating over an unreadable object
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
0
It took me a while but I've been able to get it. Here is my code:
https://code.sololearn.com/c9N3YNZDJZdp