+ 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

14th Nov 2020, 11:33 AM
Slick
Slick - avatar
3 Réponses
+ 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
14th Nov 2020, 12:09 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
That's going to be it, thanks NotAPythonNinja and TheWh¡teCat 🇧🇬 ! Such a silly problem sheesh
14th Nov 2020, 12:26 PM
Slick
Slick - avatar
+ 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
15th Dec 2020, 6:45 PM
Lam Wei Li
Lam Wei Li - avatar