+ 1

(HELP) Stuck on some coding exercises in the Python course

As the description would suggest, I'm rather stuck in regards to the Book Title and Longest Word exercises in the Python course. I'm appealing here for help because every previous attempt to get past these purely by myself has lead to me staring at the screen in demoralized frustration for five minutes before giving up and logging out. It started when I finished up the quizzes on module 5 and was going to do the exercise, but then I had to put that to one side temporarily due to COVID-vaccine induced headaches and exhaustion. I tried to come back to it when my symptoms cleared up, only to find myself at a total and utter loss. I tried just going through the next module, but I was at a loss in regards to the exercise at the end of that as well. I'm appealing for help here for the simple reason that this has got me stuck in an endless loop of anxiety-induced procrastrination with a side order of doubting wether I'm actually cut out for this or should just give up. Absent any real better options on my end, I've decided to seek help from the community. I really do want to be a programmer, but right now I'm sincerely doubting if I'm cut out for this. Any good help would be at this point would be nice.

5th Apr 2021, 3:28 PM
James Anthony Ville
18 Answers
+ 4
I want to say something motivational, but it's my bedtime (GMT+8). In short, you need to measure word length for both Book Title and Longest Word. Therefore you need to use len() method on strings: https://code.sololearn.com/cnxHOMgA02mi/?ref=app I don't see it's covered in the Python course, so I am giving you this technical hint directly. Try. And if you still get stuck, I'll try to give more hints after I wake up.
5th Apr 2021, 3:36 PM
Gordon
Gordon - avatar
+ 3
Hint is given but for more help, post whatever you did so far.
5th Apr 2021, 3:50 PM
Scarlet Witch
Scarlet Witch - avatar
+ 3
No need to give up, practice makes you better. Just keep trying
7th Apr 2021, 3:34 PM
Scarlet Witch
Scarlet Witch - avatar
+ 3
One more hint: use for loop
7th Apr 2021, 3:34 PM
Scarlet Witch
Scarlet Witch - avatar
+ 3
Hint: to print first word use [0] and for length len(your variable) and make it string
9th Apr 2021, 5:11 PM
Scarlet Witch
Scarlet Witch - avatar
+ 3
I can help you more if you post your code here...
9th Apr 2021, 5:13 PM
Scarlet Witch
Scarlet Witch - avatar
+ 2
James Anthony Ville, i can see some Type error in your code🧐
13th Apr 2021, 11:07 AM
Scarlet Witch
Scarlet Witch - avatar
+ 2
James Anthony Ville NO PROBLEM! I HAPPY YOU SOLVED YOUR PROBLEM Happy Coding : )
14th Apr 2021, 3:22 PM
Scarlet Witch
Scarlet Witch - avatar
+ 1
Your solution please Hint : Use the len function.
5th Apr 2021, 3:34 PM
Aditya
Aditya - avatar
+ 1
Update: Done with the book titles exercise. Took some work to get both the first letter and length of each line as strings and print them together within the bounds of a single print statement, but I managed to come up with what I think is a fairly compact solution. Given that I've spent the better part of an hour on this, I'm going to log off for now and attack my other unsolved problems later. Here is my code: file.open("/usercode/files/books.txt", "r") books = file.read().splitlines() for line in books print(str(line[0]) + str(len(line))) file.close()
12th Apr 2021, 4:21 PM
James Anthony Ville
+ 1
Yeah Scarlet, I was thinking I might have cocked something up transcribing that from the editor window on the problem into the comments on this.
14th Apr 2021, 3:05 PM
James Anthony Ville
+ 1
Yeah, now to get onto the Longest Word problem.
14th Apr 2021, 3:29 PM
James Anthony Ville
+ 1
Update: Finally managed to clear all of my unsolved problems. Will move on to the functional programming module in the Python course soon.
16th Apr 2021, 3:21 PM
James Anthony Ville
0
Thanks for the input. I'll take another look at the those with the whole len thing in mind and see if I have a brainwave.
7th Apr 2021, 2:59 PM
James Anthony Ville
0
Update: I've been trying to figure out the whole book titles one for a bit over half an hour now, but I'm still at a bit of a loss. I've been putting this off for so long out of anxiety that I've forgotten a good chunk of what I've learned and I have no real idea how to take the data I'm given there and turn it into the necessary output. Am I even cut out for this at all? Should I just give up on this whole programming thing? becuase it sure damn feels like it right now.
7th Apr 2021, 3:27 PM
James Anthony Ville
0
Alright
9th Apr 2021, 3:03 PM
James Anthony Ville
0
Update: I've been at this for roughly an hour now and I have a much better understanding of how I may do what needs to be done, but I still don't exactly know what to do. It's clear enough that I'm supposed to iterate through the lines with a for loop and print a string consisting of the first letter of each line and its length excluding newline characters. I still don't exactly know how to pull this off, but I have a much better picture of what needs to be done. Either way, I've been working at this for roughly an hour and seem to have hit a minor wall. I'm feeling much better about this than I was, but the path forward still isn't completely clear. To that end, I'm going to log off and come back to this on Monday. Hopefully by then I will have either had a brainwave about this or someone will have come along with the remaining bits of the answer. Perhaps both.
9th Apr 2021, 4:17 PM
James Anthony Ville
0
James Anthony Ville I'm happy for you!
17th Apr 2021, 2:44 AM
Scarlet Witch
Scarlet Witch - avatar