Question: Define a function that takes a file name (a string object) as an argument. The function should attempt to open the file in read mode,

 Define a function that takes a file name (a string object)

Define a function that takes a file name (a string object) as an argument. The function should attempt to open the file in read mode, count the number of lines in the file, and close the file object. The function should then return the line count. Name your function appropriately. Call the function and assign the returned value to a variable. Print the value stored in the variable to the console. Any exceptions (such as FileNotFoundError) that may arise when calling the function should be handled by your code. You can write the exception handling code inside the function definition, or outside, when calling the function. You are allowed to create a text file in the same folder as your Python program to test your code, but please do not try to upload your text file to Ninova, as I only need your Python file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!