+ 1
Guys hu can help me out on the "Book titles project"?
Python book titles project
5 ответов
+ 3
Show your attempt.
+ 1
Yes, Edward B. If the answer is given directly to you, you may not learn anything
+ 1
Edward B. If you check the NOTE at the end of problem.
There is written, every line except the last one contain a '\n' character at the end which denotes new line and it is also counted as 1 when you use "len" function.
You have to do some thing like this:
for i in m:
if i==lines[-1]:
print(i[0]+str(len(i)))
else:
print(i[0]+str(len(i)-1))
file.close()
Hope you understood.
0
This project is about files and exeptions (opsionally). So you should know the functions and methods mentioned in that's module lessons.
It says at attention box the readLines() method.
1- You should use it to get a list of lines in the file.
2- Then, iterate over it with a for loop.
3- During iteration, check for requirements mentioned at project.
4- Fulfill those requirements.
5- Don't forget to close the file after operating.
I would like to see your attempt if you get it 😋🙂
0
file = open("/usercode/files/books.txt", "r")
m=file.readlines()
for i in m:
print(i[0]+str(int(len(i))))
file.close()
#your code goes here
file.close()