I am working on a Python 3 program that gets string data from the program user and then writes that data to a text file. An another program that reads the data from a file and then displays that data.
The requirements are that both programs will use loops. Program #1 should use the signal QUIT to stop running. Program #2 should run until all of the data is extracted from the file.
I thought I had an understanding of reading/writing to text files in python but I'm completely stumped on this and how to run a loop that will keep going until the signal QUIT. I tried a for loop but that didn't work out so I'm assuming I would use a while loop but not sure how to make that work.
The outlook is expected to the look like the below:
Program #1 Enter a file name: test.txt Enter a string: Once upon a time Enter a string: In the west Enter a string: QUIT
Program #2 Enter a file name: test.txt Once upon a time In the west
I'm really stuck on this so if anyone could help out that would be amazing.
Sorry here is the code I have:
tf = open("test.txt", "w")
a = input("Enter a string: ")
while a != "QUIT":
print(input("Enter a string: ")
if a == "QUIT":
break