Why my code does not work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why my code does not work?

In the 5th module of Python core course there is a problem about books. Here is my code: https://code.sololearn.com/c75Ez66ZgRRG/?ref=app

20th May 2021, 9:03 PM
Kind_Cat
Kind_Cat - avatar
2 Answers
+ 3
by reading lines, you've got the end of line char ("\n") at end of each lines... but the last (if there's no empty lines at end of file)... so len() doesn't report the correct number of chars ^^ the simple to get lines without that unexpected char would be to apply .trim() merhod to string before using it as len() argument: len(i.trim())
20th May 2021, 9:10 PM
visph
visph - avatar
+ 1
Thank you very much!
20th May 2021, 9:12 PM
Kind_Cat
Kind_Cat - avatar