0
Where is the mistake of my book titles project's code?
The code is equal to the first letter of the book, followed by the number of characters in the title. For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space). file = open("/usercode/files/books.txt", "r") for x in file: code = x[0] num = len(x) print (code + len) file.close()
5 Answers
+ 8
ā ļø remember that all lines, except the last one, contain a \n at the end, which should not be included in the character count.
if x[-1] == "\n":
print (code + str(num-1)
)
else:
print(code +str(num))
+ 5
Yeah, if "\n" in x:
+ 2
Simba I'm not really understand the usage of ==
Why don't use the in operator instead of it?
0
G'day lityang have you done some debugging already? What does it print?
Line5: print (code + num)
- 2
# Try this instead of all other code:
print("H12\nT16\nP19\nG18")
# it works for today :))