I have written some code to take in users and assign tasks to them using a text file. The problem I am having is as the user inputs a task number to edit, but I don't know how to replace the line of text 12 lines above the task number that is input and this replaces the username. If there are two tasks in the text file I need to be able to use the task number line as a reference point and then replace the 12th line above that to a new username. So I basically need to replace the 12th line above the users input for every task. I have written some code to just replace the name but its erasing my whole text file.
Example of text file: (tasks.txt)
User assigned to task:
jack
Task Title :
Fly
Task Description:
Fly to the moon
Task Due Date:
2020-02-20 Date Assigned:
2020-02-18
Task Completed:
No
Task number:
1
The code of the effected block so far is:
with open('tasks.txt') as xxaz:
main2 = "Task number:" + "\n" + str(review)
aa = xxaz.read()
if main2 in aa:
print(str(main2) + "\n")
edit = input("Enter ""1"" to edit the user assigned to task, ""2"" to change the due date or ""3"" to change the completion status.\n")
if edit == "1":
new_name = input("Please enter a new user name")
lines = open('tasks.txt').read().splitlines()
lines[2] = new_name
open('tasks.txt','w').write