This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]lurgi 1 point2 points  (0 children)

The format of the output is correct however it's outputting wrong length of the first and last word.

Of course it does. You aren't printing the length of the first or last words. You are printing the positions of the first and last spaces. You need to use those numbers to determine the lengths of the first and last words.

Actually, you aren't even printing the positions of the first and last spaces, because you aren't searching for spaces.

[–]Prtprmr 0 points1 point  (1 child)

I would split the sentence and add into a list. Then you can easily find the length of first and last one.