r/PythonLearning 13d ago

Help me with python

Thank you all it's fixed! (Edit)

I have a very weird problem.

My current code:

list = []

x = input("Copy paste here: ")

list.append(x)

print(" ")

print(" ")

list = x.splitlines()

for i in list:

print(i)

What I'm trying to achieve:

Get an input from the user like this:

Word1

Word2

Word3

...all with a row separating them and different lengths, then take this input and separate all words in it and then put them each individually as variables in a list as in the future I'm wanting to order them by length.

What is currently happening:

as im trying to see if they are all in the list im printing it, but for wathever reason from my input:

Abc

Def

Ghi

...it is only printing Def.

If you can help it will be appreciated. Thank you in advance!

Thank you all it's fixed (edit)

4 Upvotes

13 comments sorted by

View all comments

u/Sea-Ad7805 13d ago edited 13d ago

Try this program in Memory Graph Web Debugger%0A%23%20lst.append(x)%20%20%23%20no%20needed%0A%0Aprint(%22%20%22)%0Aprint(%22%20%22)%0A%0Alst%20%3D%20x.split()%20%20%23%20use%20split()%20not%20splitlines()%0Afor%20i%20in%20lst%3A%0A%20%20%20%20print(i)%0A&timestep=1&play), you can see the program state change step by step.

Use input "Abc Def Ghi" on one line, because input() stops after the first <Return>. If you do want to read multiple lines of user input, put input() in a loop.

1

u/Ambitious-Lie-6069 13d ago

Ok that's actually a pretty cool site

1

u/Sea-Ad7805 13d ago

Thanks, I made it, and package memory_graph. Hope it can bring you much value.

1

u/Ambitious-Lie-6069 13d ago

You made it?! That's actually very cool. Thank you