7. Write a python program to calculate the lines number in a file, a.txt.
The output is:
Original file a.txt:
Welcome to
www.freelearningpoints.com
You can learn Python tutorials and
practice with exercises
Expected Answer:
The number of lines in the file: 4
Sample Answer:
def line_lengthy(file_name): with open(file_name) as f: for i, l in enumerate(f): pass return i + 1 print("The number of lines in the file: ",line_lengthy("a.txt"))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)