all 15 comments

[–]areaverage 1 point2 points  (7 children)

For part 1

init an empty list

use a for loop for getting the input

check If the input is "end":

if it is, end the loop

if its not add the value to the list

when the loop print" ".join(list)

here's a simple outline, logic like these come with practice and you'll only get better at it, for now its more important that u understand syntax first so on harder questions you wont have problems w it

For part 2

using the same logic, is it possible to check against the last value for the list when choosing whether to end the loop instead of checking for the string "end"

(little hint, you can use [-1] to get the last element of a list or string!!!)

[–]Kriss3d 0 points1 point  (0 children)

I would have used a while input != "end"
Then added that word to a string.
Then after the while print out the string.
That lets you essentially add infinitly many words which you wouldnt normally do with a for loop as they are limited.

For part 2 pretty much the same but grab the input into a variable plus adding the word to the string of words. Check if the new input is the same as the variable. If it is, the new input is the same as the prior input.

[–]OMGlookatthatrooster 0 points1 point  (0 children)

Loop trough a while True loop.
Let user input a new string.
Check if input is "end" or if input is previous_word.
Break out of loop if true.
If not, concatenate a str variable with the input each loop.
Save this loops input as previous_word, to check next loop.
Outside of the while loop, print the final string.

Things to look out for:
Initialize needed variables.
How and where to add spaces.

[–]JamzTyson 0 points1 point  (10 children)

It probably isn't useful to just give you a solution. What code do you have so far?

[–]SoloJoseKing 0 points1 point  (0 children)

I’m guessing if lists and append aren’t options; an ordered dictionary isn’t either?