Skip to content

sasikanth6076/ASSIGNMENT-4-Files-Exceptions-and-Errors-in-Python

Repository files navigation

ASSIGNMENT-4-Files-Exceptions-and-Errors-in-Python

Module 5: Files, Exceptions, and Errors in Python

Task 1: Read a File and Handle Errors

Problem Statement: Write a Python program that:

  1. Opens and reads a text file named sample.txt.
  2. Prints its content line by line.
  3. Handles errors gracefully if the file does not exist.

Expected Output:

If the file exists:

Line 1 : This is a sample text file
Line 2 : It contains multiple lines

If the file does not exist:

the file example.txt was not found

Task 2: Write and Append Data to a File

Problem Statement: Write a Python program that:

  1. Takes user input and writes it to a file named output.txt.
  2. Appends additiona l data to the same file.
  3. 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 additonal text to append: learning file handling in python Data Successfully appended.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages