Lab7_PythonFileHandling
Lab7_PythonFileHandling
2. Writes three lines of text to the file using write(), where each line includes a person's
name and age, separated by a comma (e.g., Sarah,25).
3. Reads the file using read() and prints the entire content.
5. Reads and prints only the first two lines of the file using readline().
2. Writes five lines of text to the file, where each line contains a student's name, age, and
grade, separated by a comma (e.g., Ali,20,16).
3. Adds three additional lines: one empty line and two lines containing special characters
(e.g., one line containing ### and another line @@@).
5. Appends two more student records to the file, by asking the user to input these new
records.
6. Reads and prints only the second and fourth lines using readline().
7. Reads and prints only the lines that contain valid student records (ignoring the empty
lines and special character lines (having # and @)).
8. Deletes the file records.txt after all operations are complete. The program needs to
check if the file exists before performing deletion.
Ensure that you use exception handling to manage potential errors, such as issues with
file access, missing files, or permission errors.