Question: open\_file(): This function takes no parameters, then uses the try-except format to prompt for a filename, open the data file and return the file pointer if successful. Your function should be able to catch the error and print the error message if it fails to open; and then reprompt. It will reprompt

I have written this code but not sure if it is correct and meets the requirements mentioned above. Can anyone please help me?

```
def open_file():
    try:
        fp = open(file, 'r')
        return fp
    except FileNotFoundError:
        fp = open('congress.txt','r')

file = open('congress.txt', 'r')
for line in file:
    print(line)

```

Answer: 
Looks like an assignment so I won't post a full-blown solution, but I can at least answer the explicit questions: your code obviously doesn't meet the requirements - it doesn't prompt for another file name if the first one is not found an doesn't print any error -, now it does something that's not only not required but also totally unexpected - it tries to open some hardcoded filename if the asked one isn't found.

Just a hint: repeting an operation is usually done using a `for` or `while` loop.
I reworked it a bit, but this will do what you want it to do.

```
def open_file():
    try:
        file_name = input("What is the filename? ")
        with open(file_name) as fp:
            new_doc = fp.read()
        return new_doc
    except FileNotFoundError:
        print("File not found")
        new_doc = open_file()
        return new_doc

file = open_file()
print(file)

```