Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 6 subjective questions Files and Exceptions; Regular Expressions

INT108 — Python Programming 20 questions with model answers. Write yours first, then compare.

Read the notes Practice MCQs
  1. Question 1 of 20

    Define a text file. Explain how Python represents and processes text-file data.

  2. Question 2 of 20

    Explain the syntax and purpose of Python's open() function. Describe the commonly used file modes.

  3. Question 3 of 20

    Describe the different methods used to read data from a text file in Python. Compare read(), readline(), and readlines().

  4. Question 4 of 20

    Explain how variables of different data types can be written to a text file. Why is conversion sometimes required?

  5. Question 5 of 20

    Distinguish between writing and appending to a file. Illustrate the difference with Python code.

  6. Question 6 of 20

    Develop a Python program that copies a text file while numbering its lines. Explain how the program handles resources and errors.

  7. Question 7 of 20

    Explain how Python programs work with directories and file paths using the pathlib module.

  8. Question 8 of 20

    What is pickling in Python? Explain how an object is serialized and deserialized.

  9. Question 9 of 20

    Compare pickling with storing data in a text file. Include the advantages, limitations, and security concerns of pickling.

  10. Question 10 of 20

    What is an exception? Explain how a ZeroDivisionError occurs and how it can be handled.

  11. Question 11 of 20

    Describe the structure and execution flow of a try-except statement. How can multiple exception types be handled?

  12. Question 12 of 20

    Explain the purpose of the else block in exception handling. How is it different from code placed directly after a try-except statement?

  13. Question 13 of 20

    Explain FileNotFoundError and write a program that handles it while reading a file.

  14. Question 14 of 20

    Design a robust Python function that divides two user-supplied values and records the result in a file. Handle likely input, arithmetic, and file exceptions.

  15. Question 15 of 20

    Define a regular expression. Explain the roles of literal characters, metacharacters, and raw strings in Python patterns.

  16. Question 16 of 20

    Describe the major types of regular-expression elements: character classes, quantifiers, anchors, groups, and alternation. Give examples.

  17. Question 17 of 20

    Explain the use of re.match(). Compare it with re.search() and re.fullmatch().

  18. Question 18 of 20

    Construct and explain regular expressions for validating an email address, a ten-digit mobile number, and a date in DD-MM-YYYY format.

  19. Question 19 of 20

    Explain how regular expressions can be used in web scraping. State the steps involved and the main limitations of this approach.

  20. Question 20 of 20

    Write and explain a Python program that downloads a web page and extracts email-like strings using regular expressions. Include appropriate error handling.

That's unit 6

Long answers stick best when they're tested again soon. Run the MCQs on this unit, then come back to the questions you found hardest.