-1

The output i receive is "none" while in the .txt file is already 3 given names and i suppose to add one more through input.

Add a new member: Solomon Right
None

Process finished with exit code 0

That is my code:

newUserMember = input("Add a new member: ")

file = open("/Users/nikitalutsai/Downloads/members.txt", 'r')
content = file.readlines()
file.close()

content.append(newUserMember + "\n")

file = open("/Users/nikitalutsai/Downloads/members.txt", 'w')
content = file.writelines(content)
print(content)
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70

1 Answers1

0

writelines is returning None as mentioned in the comment (see here). If you want to append to a file you should have a look at this answer.

Do something like:

with open("/Users/nikitalutsai/Downloads/members.txt", "a") as myfile:
    myfile.write(input("Add a new member: "))
Koedlt
  • 4,286
  • 8
  • 15
  • 33
elo98
  • 1
  • 2