Skip to content

Instantly share code, notes, and snippets.

@computer-tutor
Last active May 8, 2021 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save computer-tutor/2a5562d4e07027581b78b31d59c49df4 to your computer and use it in GitHub Desktop.
Save computer-tutor/2a5562d4e07027581b78b31d59c49df4 to your computer and use it in GitHub Desktop.
def func_start_A(l): # function to count lines starting with ‘A’
c = 0 # c is the count of such lines
for line in l:
if line.startswith('A'):
c += 1
return c
f1 = open('LINES.txt', 'r')
l = f1.readlines() # creates a list of all the lines in the file
print('Number of lines starting with A in the file LINES.txt is', func_start_A(l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment