0

In the below code, why am I getting a syntax error on the last line[file.close()]. In the error message. Pls help

file = open("/usercode/files/books.txt", "r") g = file.readlines() for i in g: if '\n' in i: print((i[0]) + str(len(i)-2)) else: print((i[0] + str(len(i))) file.close()

31st Jan 2021, 2:24 PM
Amit Manyal
Amit Manyal - avatar
4 ответов
+ 1
Python.Sorry forgot to mention that 😅
31st Jan 2021, 2:30 PM
Amit Manyal
Amit Manyal - avatar
+ 1
you could edit the question/tag ;) the error is just before the mentioned line: mismatch parenthesis in 'else' block ^^ print((i[0]) + str(len(i))) (but you could avoid i[0] parenthesis)
31st Jan 2021, 2:35 PM
visph
visph - avatar
0
Thanks bro, Came out to be a silly mistake 😅
31st Jan 2021, 2:39 PM
Amit Manyal
Amit Manyal - avatar