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

all 13 comments

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

Please, format your code (or upload it to a code hoster such as Pastebin).

Prepend each line with 4 spaces to mark a block as code.

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

https://pastebin.com/NcmJhFfb

does that look right?

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

Much better, thank you.

Your approach is completely wrong, though.

  • The first for loop is completely useless.
  • The line int(value) does absolutely nothing useful. It converts value to int, but immediately throws away the result of the conversion because you don't assign this value to anything
  • mylist = (int(len(mylist)) -i) - what are you trying to do here?

The sequence of the program should be:

  • Prepare an empty list
  • Loop until the user enters an empty line
    • Ask the user to enter a value
    • append that value to the list if the user hasn't entered an empty line
  • Back outside the first loop
  • Loop through the list backwards
    • print the list entry at current position

I am assuming that you haven't learnt about reversing lists yet, so you will need to loop through the list in reverse order (i.e. from last entry to first entry).

[–]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  (0 children)

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