0

What I'm trying to do is create a function that saves the user's answer to a prompt and puts it into a .txt file.

I use sys to do this, but it failed to properly put the user's answer into the file. it deleted the user's answer from the .txt file to make a new space for the newest one.

are there any other modules that could help with my request?

Theodore
  • 283
  • 1
  • 3
  • 15

1 Answers1

3

i think you need something like this

question = input("Your question: ")


def write_ans_to_file(answer, filename="answers.txt"):
    with open(filename, "a") as e:
        e.write(answer)
        e.write("\n")

write_ans_to_file(question)
George Imerlishvili
  • 1,816
  • 2
  • 12
  • 20