title: How to exit for loop once valid file name is provided and give 3 chances for correct input
body: <p>I am trying to write a for loop that will give a user 3 tries to provide the correct filename. What is the best way to do this or best practice? </p>
  
  <pre><code>for n in [1,2,3]:
      try:
          user_inp = input('Please provide the filename: ')  # Prompt user for file name
      # Need help here..
      # If the filename isn't found, python will give the following error: FileNotFoundError: [Errno 2] No such file or directory: 
      # If that happens, I need it to print the except statement and try again 
      # However, if the filename is correct or "FileIsFound" I need it to exit the loop--using ' break ' ?         
      except:
            print('Invalid file name, try again please')
      # Would be great if we could add a counter here like: print('You have', n, 'tries remaining') 
      continue
  
  file_open = open(user_inp) # open file --load in memory 
  
  for line in file_open:  # remove /n at the end of each line
  line = line.rstrip()  # print statements add /n = newlines and text docs usually have /n in them
  # this for loop will remove/strip the /n at the end of each line
  
  read_file = file_open.read()  # reads entire file 
                                # NOTE: if you are dealing with large files, you may want to consider using a conditional statement to find what you are searching, extracting, etc instead of reading the entire file
  
  
  print(read_file.upper())  # Prints file contents in upper case 
  </code></pre>
  
  <p>I would like to know how to do this with a try and except statement. Thank you!</p>
  
  <p>Cheers. </p>