Book titles code not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Book titles code not working

My code for book titles is giving me an invalid syntax error on the else line but i have no idea why. Can anyone help please? file = open("/usercode/files/books.txt", "r") lines = file.readlines() #your code goes here for line in lines: if "\n" in line: print(line[0] + len(line-1) else: print(line[0] + len(line) file.close()

11th Mar 2023, 8:11 PM
Craig Yates
Craig Yates - avatar
4 Answers
+ 4
What does the error message say? Make sure you printing the actual number of a line and it's content
11th Mar 2023, 8:51 PM
Lamron
Lamron - avatar
+ 3
Closing parentheses are missing in both print statements
11th Mar 2023, 10:04 PM
Oma Falk
Oma Falk - avatar
+ 3
You are missing the Parenthesis.. #yours >> print(line[0] + len(line-1) >> print(line[0] + len(line) #fixed >> print(line[0] + len(line-1)) >> print(line[0] + len(line)) Syntax Error should not appear anymore.
11th Mar 2023, 10:22 PM
◦•●◉✿𝕀ℕ𝔻𝕀✿◉●•◦
◦•●◉✿𝕀ℕ𝔻𝕀✿◉●•◦ - avatar
+ 1
Ah, thanks so much everyone!
13th Mar 2023, 2:40 PM
Craig Yates
Craig Yates - avatar