diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..5c80254d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} diff --git a/F/file-reader/README.md b/F/file-reader/README.md new file mode 100644 index 00000000..86eacded --- /dev/null +++ b/F/file-reader/README.md @@ -0,0 +1,22 @@ +### File Reader + +This is a simple Python program that reads and displays the content of a text file. It allows you to specify the file name, and it will display the contents of that file. The program handles common error cases more gracefully. + +#### Usage + +1. Run the program using a Python interpreter. +2. You will be prompted to enter the name of the file you want to read. +3. The program will then attempt to read and display the content of the specified file. +4. If the file is found and can be read, its content will be displayed. +5. If the file is not found, an error message will be shown. +6. If any other error occurs during file reading, an error message will be displayed. + +#### Program Features + +- Graceful handling of errors: + - If the specified file is not found, it will display a user-friendly error message. + - If any other error occurs during file reading, it will display an error message with details. + +#### Prerequisites + +- Python 3.x diff --git a/F/file-reader/file-reader.py b/F/file-reader/file-reader.py new file mode 100644 index 00000000..9e10a4f3 --- /dev/null +++ b/F/file-reader/file-reader.py @@ -0,0 +1,11 @@ +filename = input("Enter the name of the file to read: ") + +try: + with open(filename, 'r') as file: + content = file.read() + print("File content:") + print(content) +except FileNotFoundError: + print(f"File '{filename}' not found.") +except Exception as e: + print(f"An error occurred: {e}")