Page 83 - PYTHON-12
P. 83

#Program to read data from data file in append mode

               af=open("test.txt",'a')

               lines_of_text = ("One line of text here”,\


                                “and another line here”,\

                                “and yet another here”, “and so on and so forth")

               af.writelines('\n' + lines_of_text)


               af.close()























               Program 14:  Write a Program to read data from data file in read mode and count the
               particular word occurrences in given string, number of times in python.


               Solution:

               #Program to read data from data file in read mode and

               #count the particular word occurrences in given string,


               #number of times in python.

               f=open("test.txt",'r')

               read=f.readlines()


               f.close()

               times=0 #the variable has been created to show the number of times the loop runs

               times2=0 #the variable has been created to show the number of times the loop runs


               chk=input("Enter String to search : ")
   78   79   80   81   82   83   84   85   86   87   88