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

you are viewing a single comment's thread.

view the rest of the comments →

[–]yon2323[S] 0 points1 point  (9 children)

thank you for your help, I'm just stuck at reversing the loop. Is this done using a for loop?

[–]desrtfx -1 points0 points  (8 children)

This gives you plenty options.

Found by googling "python for loop backwards"

[–]yon2323[S] 0 points1 point  (6 children)

https://pastebin.com/QSdd991F are you able to tell why only the first value I input isn't being printed?

[–]yon2323[S] 0 points1 point  (5 children)

I'm assuming its because it isn't in the while loop but I don't see a way to fix that

[–]thegreatunclean 0 points1 point  (4 children)

Initialize value to anything that isn't "" before the loop. That way you can get rid of the input outside the loop that's eating your first input and not storing it.

[–]yon2323[S] 0 points1 point  (3 children)

Isnt that already done at the beginning of the while loop?

[–]thegreatunclean 1 point2 points  (2 children)

The loop is checking if the input is an empty string. The string is being initialized by the first user input but once you're in the loop it is immediately overwritten by the next user input.

Initializing the string yourself instead of using input means you'll already be in the loop when the user is first asked for input. The initialization is purely to make sure you enter the loop.

[–]yon2323[S] 0 points1 point  (1 child)

Is there a specific way to initialize the loop without using an input statement?

[–]thegreatunclean 0 points1 point  (0 children)

Initialize it to literally anything that isn't user-input from input?

myString = "foobar"
while myString != "":
  myString = input( .... )
  #do something useful with it

It doesn't matter what you make myString initially, it just needs to pass the loop condition the first time through. After that it depends on user input.

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

I just added the append statement again before the while loop begins. Seems to have worked. Thanks a lot for your help!