¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita0
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()
4 Respuestas
+ 4
What does the error message say?
Make sure you printing the actual number of a line and it's content
+ 3
Closing parentheses are missing in both print statements
+ 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.
+ 1
Ah, thanks so much everyone!