Write Python Program to Count the Number of Lines in a Text File


Topic: Write Python Program to Count the Number of Lines in a Text File

Solution

fname = input("Enter file name: ")
num_lines = 0
with open(fname, 'r') as f:
    for line in f:
        num_lines += 1
print("Number of lines:")
print(num_lines)



List all Python Programs