[Type B] File Handling – Chapter 5 Sumita Arora

|
Table of Contents

9. If you use the code of Q.8 with pl.txt (created in solved problem 16), what would be its output?

p1.txt from solved problem 16 contains:

Answer: The output of the provided code using pl.txt:

Output
1

Explanation:

The code reads the content of pl.txt, counts the number of lines (nl variable), and prints the count after reading all lines in the file. In the pl.txt file, there is one line, so the output is 1.

Note: If the file ‘pl.txt’ does not exist in the same directory as the Python script, the code will raise a FileNotFoundError. You may want to add error handling code to handle such cases in a real-world scenario.

"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *

One Comment