Answered step by step
Verified Expert Solution
Link Copied!

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,

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions