title: The correct function to loop to text file
body: <p>Could anyone help with the correct way to loop to a text file. I have an issue with my code at the moment where it is writing task numbers to a text file but all the numbers are returning task 1. My second task is not returning task 2 and the third task not returning task 3. They are all returning task 1. I would like for the task number to change every time i add a task to the text file. Would a simple way to be able to call on a specific task later in the code be possible?</p>
  
  <p>task example:</p>
  
  <blockquote>
    <p>User assigned to task:</p>
    
    <p>jack</p>
    
    <p>Task Title:</p>
    
    <p>jog</p>
    
    <p>Task Description:</p>
    
    <p>Go jogging</p>
    
    <p>Task Due Date:</p>
    
    <p>2020-02-08</p>
    
    <p>Date Assigned:</p>
    
    <p>2020-02-07</p>
    
    <p>Task Completed:</p>
    
    <p>No</p>
  </blockquote>
  
  <p>requested output:</p>
  
  <blockquote>
    <p>User assigned to task 1:</p>
    
    <p>jack</p>
    
    <p>Task Title:</p>
    
    <p>jog</p>
    
    <p>Task Description:</p>
    
    <p>Go jogging</p>
    
    <p>Task Due Date:</p>
    
    <p>2020-02-08</p>
    
    <p>Date Assigned:</p>
    
    <p>2020-02-07</p>
    
    <p>Task Completed:</p>
    
    <p>No</p>
  </blockquote>
  
  <p>The code i have so far is as follows. It is writing numbers to the text file but they are all labelled task 1 and the next task is not changing to task 2:</p>
  
  <pre><code>count = 0
  
  def add_task(count):
   if menu == "a" or menu == "A":
      with open( 'user.txt' ) as fin :    
          usernames = [i.split(',')[0] for i in fin.readlines() if len(i) &gt; 3]
          task = input ("Please enter the username of the person the task is assigned to.\n")
      while task not in usernames :
          task = input("Username not registered. Please enter a valid username.\n")
  
      else:
          task_title = input("Please enter the title of the task.\n")
          task_description = input("Please enter the task description.\n")
          task_due = input("Please input the due date of the task. (yyyy-mm-dd)\n")
          date = datetime.date.today()
          task_completed = False
          if task_completed == False:
              task_completed = "No"
          else:
              task_completed = ("Yes")
          with open('tasks.txt', 'a') as task1:
              count = count + 1
              task1.write("\nUser assigned to task" + str(count) + "\n" + task + "\nTask Title :"  + "\n" + task_title + "\n" + "Task Description:\n" + task_description + "\n" + "Task Due Date:\n" + task_due + "\n" + "Date Assigned:\n" + str(date) + "\n" + "Task Completed:\n" + task_completed + "\n")
              print("The new assigned task has been saved")
  add_task(count)
  </code></pre>