+ 2

Python Core Lesson 51 Book Titles

Hey guys. This is the code I used to solve this problem and I've even tested this outside of SL and it works fine. Yet the learning module does not accept it. for content in list: content = content.capitalize() code = str(len(content)) code_letter = content[0] print(code_letter+code) file.close()

19th Dec 2021, 7:06 PM
Christopher Cox
Christopher Cox - avatar
2 Respostas
0
assuming you are running this, right? If so, I am getting incorrect lengths for the strings (see below) file = open("/usercode/files/books.txt", "r") list = file.readlines() for content in list: content = content.capitalize() code = str(len(content)) code_letter = content[0] print(code_letter+code) file.close() Your Output H13 T17 P20 G18 Expected Output H12 T16 P19 G18
19th Dec 2021, 7:20 PM
David B
0
You would need to change your code to display the correct lengths. Remember that the last title doesn't have a line break. If you having trouble try printing your list
19th Dec 2021, 7:23 PM
David B