-4
user = input('Create a Username: ')
passw = input('Create a Password: ')
f = open("users.txt", "a")
combine = "|".join("\n" + user + passw)
f.write(combine)
f.close()

I created a variable where I can combine both of the username and password and write It in the users.txt file.but when I try to combine "admin" and "99" It goes like this: a|d|m|i|n|9|9|.

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • 1
    See https://stackoverflow.com/questions/5082452/string-formatting-vs-format-vs-string-literal – dh762 Aug 26 '20 at 07:15
  • ``"|".join(["\n" ,user , passw])``, because string is a iterable & join is iterating over each value in string – sushanth Aug 26 '20 at 07:16
  • ```open("users.txt", "a").write(input('Create a Username: ') + '|' + input('Create a Password: '))``` – Sayan Dey Aug 26 '20 at 07:18
  • strings are iterable, str.join(.., iterable) works on iterables. So it combined each character of the combined string `"\n" + user + passw` to each other and seperates by | ... – Patrick Artner Aug 26 '20 at 07:18

1 Answers1

0

Do simple old concatenation:

user = input('Create a Username: ')
passw = input('Create a Password: ')
f = open("users.txt", "a")
combine = user + "|" + passw
f.write(combine)
f.close()
thisisjaymehta
  • 614
  • 1
  • 12
  • 26