title: Opening a file based on user's input python
body: <p>How to open a file from the list of given files based on the user's input which is an integer </p>
  
  <pre><code>print("Enter 1.tp.txt\n2.c17testpat.pat\n3.c432testpat.pat\n4.c499testpat.pat\n5.c1335testpat.pat\n6.c6228testpat.pat")
  user = input("Enter a number")
  if user == 1:
      filename = "tp.txt"
  elif user == 2:
      filename = "c17testpat.pat"
  elif user == 3:
      filename = "c432testpat"
  elif user == 4:
      filename = "c499testpat.pat"
  elif user == 5:
      filename = "c1355testpat.pat"
  elif user == 6:
      filename = "c6288testpat.pat"
  
  fp = open(filename)
  </code></pre>
  
  <p>is there any other way to do it in python </p>
  
  <p>this caused NameError: name 'filename' is not defined</p>