========================================ASSIGNMENT 4:=====================================================
====================Module 5: Files, Exceptions, and Errors in Python=================================
Task 1: Read a File and Handle Errors Problem Statement: Write a Python program that:
- Opens and reads a text file named sample.txt.
- Prints its content line by line.
- Handles errors gracefully if the file does not exist. file is readop.py Expected Output: Reading file content: Line 1: This is a sample text file. Line 2: It contains multiple file.
===========================Task 2: Write and Append Data to a File===============================
Problem Statement: Write a Python program that:
- Takes user input and writes it to a file named output.txt.
- Appends additional data to the same file.
- Reads and displays the final content of the file.
Expected Output: For example, if the user enters 25, the output should be:-
Enter text to write to the file:Hello, Python! Data successfully written to output.txt. Enter additional text to append:Learning file handling in python. Data successfully append Hello, Python! Learning file handling in python.