Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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) 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started