title: Generate a ID, check if it exists, if yes loop until new ID is generated
body: <p>I am not sure what is wrong with below logic. Task is to generate a ID, check if it exists in the file(Sample.txt) and if it is already there then generate a new code until a unique one is created. Whenever a unique ID is created at the initial stage it will goto else loop. In case if an existing ID is generated it will first goto if loop, generate a new ID but then will not compare it again, instead directly jump to else loop adding duplicate ID to the file.</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import random
  import string
  import os.path
  
  # Take user inputs
  
  NetID = input("Enter the NetID: ")
  CompTemp = input("Enter the Compliance template: ")
  Channel = input("Enter the Channel: ")
  Env = input ("Enter the environment 'P' or 'T': ")
  Const = "WG"
  Var1 = str((random.randint(0,9)))
  Var2 = random.choice(string.ascii_uppercase)
  #i=0
  
  FSID=Const+Channel+NetID+Var1+Env
  print("Original FSID: ", FSID)
  
  datafile = "C:\\Work\\Sample.txt"
  f2=open(datafile)
  
  # Define function
  def CrtFSID():
      """ Generate FSID"""
      global FSID
      Var1 = str((random.randint(0,9)))
      FSID = Const+Channel+NetID+Var1+Env
      print("New FSID code case 1: ", FSID)
      return FSID
  
  for line in open("C:\\Work\\Sample.txt", "r"):
      if FSID in f2.read():
          print("generate new FSID code")
          CrtFSID()
          print("Changed FSID is: ", FSID)
          continue
     else:
         f=open(datafile, "a")
         f.write("Adding new FSID %s\r\n" % FSID)
         print("I am in else loop")
         f.close()
         break
  
  print("Unique FSID added into the file: ", FSID)
  </code></pre>
  
  <p>The Shell output:</p>
  
  <pre><code>Enter the NetID: KL123
  Enter the Compliance template: ABC_01
  Enter the Channel: TB
  Enter the environment 'P' or 'T': P
  Original FSID:  WGTBKL1239P
  
  generate new FSID code
  New FSID code case 1:  WGTBKL1237P
  Changed FSID is:  WGTBKL1237P
  
  I am in else loop
  Unique FSID added into the file:  WGTBKL1237P
  </code></pre>