Book Title Troubles | Sololearn: Learn to code for FREE!

+9

Book Title Troubles

I've been trying out the book title challange in the python tutorial and I think I may be going a bit insane. When i run the code below, I get exactly the same output as Sololearn, but it's wrong. Can anybody shed some light on my mistake? https://code.sololearn.com/c7GU6QPrFd37/?ref=app

11/14/2020 11:33:49 AM

Slick

3 Answers

New Answer

+4

Slick , it is mentioned in the task with "!" that readlines function adds a newline character "\n", so I think that's the problem. One possible solution you can see in the code. Hope it helps you. https://code.sololearn.com/cC1xGDRkvg9r/?ref=app

+3

That's going to be it, thanks NotAPythonNinja and TheWh¡teCat 🇧🇬 ! Such a silly problem sheesh

+2

A simpler way with 5 lines of code. A simple explanation, loop through all lines, and if a line has trailing/ending "\n" remove it from the count of the length. https://code.sololearn.com/cdaPdMWWeN3W/?ref=app