Assignment 3 and 4
Assignment 3 and 4
10. Define an anonymous function (lambda function) that squares a given number. Use the
lambda function to square the numbers 1 to 5 and print the results.
Assignment 4
Attempt ALL Questions
1. What are different file modes in file handling? Explain
2. Differentiate functions write() and writelines() in regard to file handling using an
example.
3. Differentiate functions read(), read(20) readline() and readlines () in regard to file
handling using an example.
4. Write a Python program to create a new file.
5. Write a Python Program to Write Content in the file.
6. Write a Python Program to delete the file.
7. Write a Python Program to Copy the content from one file A to another file B using
Exception Handling.
8. Write a Python script that attempts to open a non-existent file. Use the try and except
clauses to handle the FileNotFoundError and print a custom error message.
9. Perform the following operations on the file:
a) Read and print the first 10 characters
b) Move to the 20th character
c) Read and print the next 15 characters
d) Move 10 characters back from current position
e) Read and print the next 10 characters
f) Move to the beginning of the file
10. Explain with an example how the seek () function works, including its arguments and
how it affects file reading/writing.