Thursday, 14 November 2019

Write a Python program with function to count the number of lines in a text file ‘ 'STORY.TXT’ which is starting with an alphabet ‘A’.

def countlines():
     file=open("D:\story.txt.txt")
     lines=file.readlines()
     count=0
     for word in lines:
          if word[0]=="A" or word[0]=="a":
               count=count+1
     print("total lines",count)
     file.close

#main program
countlines()

Input
file name:  story.txt

abcdefoiioioio
h8uhyhy8
Ai9hpu
u8y8887
a9j-j8okjioij


output

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
============== RESTART: C:/Users/Student/Desktop/12cs/fi-21.py ==============
total lines 3
>>> 

1 comment:

  1. My output is not coming and no error now what should i do

    ReplyDelete