I am new to Python and i want to know how to combine a String with all the elements of a List and then save Output in a .txt File. But the window just open and close immediately because the code is wrong. This is my code:
List = [1, 2, 3, 4, 5]
String = input("Please enter a name: ")
Output = String + List
print(Output)
f= open("Text.txt","w+")
f.write(Output + "\n")
f.close()
I am expecting to see this results:
Please enter a name: Username
Username1 Username2 Username3 Username4 Username5
And in the Text File like this:
Username1
Username2
Username3
Username4
Username5
How am i supposed to do this? If the question is not clear please let me know. My first language is not English so is hard for me to explain. Thanks for your time :)