0

Book titles python

Can someone help with the book titles project I just cant solve it

14th Apr 2021, 11:38 AM
Daniel Moshenashvili
Daniel Moshenashvili - avatar
2 ответов
0
Daniel Moshenashvili show your attempt first
14th Apr 2021, 11:58 AM
CHANDAN ROY
CHANDAN ROY - avatar
0
Just began coding last week, so I am attempting to help you solve book titles with using logic, and in return would ask others to help me with my logic, understanding, and best practices to think through these problems. With what has been taught so far. (I've seen a lot of answers to this exercise that are outside the scope of what has been in the tutorial) #For the more advanced, understand I am new, and this is for those like me. The first thing I did was output the text file to see what's in it : print(file.read()) **to be clear, I am not doing any coding, basically I want to see this txt file** Then I wanted to see what it looked like in a list, so I print(file.readlines()) The output was a list: ['Harry Potter\n', 'The Hunger Games\n', 'Pride and Prejudice\n', 'Gone with the Wind'] Problem statement wants: a)First letter of title b)the length of the string So I KNOW I am going to need a loop to run through each element in this list of books. ISSUE: len function is counting the \n as a character SOLVE: we were taught the list functions but not the .replace so inside my for loop I decided replace the \n with "" , **I first tried .insert but didn't work** I was shocked when it turned green, and a simple for loop (3 lines) was all that it took. Honestly, it took me some time to ponder on it, and I pushed the run button through every step to understand exactly what was happening. this is the best I got, but I think the logic part of this is starting to sink in for me, and I just wanted to share
18th Apr 2021, 7:46 PM
Thomas
Thomas - avatar