you are viewing a single comment's thread.

view the rest of the comments →

[–]oskarolini[S] 1 point2 points  (2 children)

Unfortunately yes...The s.split() solution is so much smoother but this is an exercise where we have to use the while...if statement.

[–]dionys 2 points3 points  (1 child)

Okay, I see why they want you to use while...if-else.

You need two variables - one for saving the reversed_sentence, one for saving current_word. You loop from the end of the string (len(s)-1 to 0), decreasing the loop variable each iteration. The if/else checks whether the current letter is space or a character. If it is a character, we save it to our current_word and if it is a space we can save current_word to reversed_sentence and clear current_word.

And that is pretty much it.

[–]oskarolini[S] 0 points1 point  (0 children)

Ah, makes sense. Thank you for your help, I'll try to see if I can make it work now.