+ 1

The last task in Python Intermediate course. What's wrong? Answer me only if you've passed this course

You should remember the task. That is to encode book titles. I can't pass it. There is the code: file = open("/usercode/files/books.txt", "r") #your code goes here content = file.readlines() for x in content: x.split() for x in content: encode = "" for y in x: encode += y[0] print(encode) file.close() Can you explain me, what's wrong with the code?

19th Feb 2022, 7:09 PM
GUMPERT
GUMPERT - avatar
1 Resposta
+ 3
Delete your first loop, it doesn't save the returned value and isn't actually used so it is useless. In the inner loop split() x so that y is each word from the current line of the file. Then your code should work. Like; for y in x.split(): ...
19th Feb 2022, 7:42 PM
ChaoticDawg
ChaoticDawg - avatar