Computer Science, asked by pranavsajeevan2004, 1 month ago

Write a Python program having user defined function to do the following
1)to create a file abc.txt to store some lines accepted from user using a function crt()
2)to remove all the lines that contain the character 'a' in a file abc.txt and write to another file notes.txt using remove()​

Answers

Answered by QwertyPs
0

Here's the Solution

1st Part

def crt():

   with open('abc.txt','a') as b:

       ans='y'

       while ans=='y':

           lines=str(input("Enter line to enter :"))

           b.write(lines)

           b.write('\n')

           ans=str(input("Want to enter more? (y/n) -"))

           

crt()

___________________________________________

2nd Part

def remove():

   with open('abc.txt','r') as b:

       with open('notes.txt','a') as f:

           a=b.readlines()

           lst=[]

           for line in a:

               for m in range(0,len(line)):

                   lst.append(line[m])

               search='a'

               if search in lst:

                   f.write(line)

               lst=[]

remove()

*Note= The 2nd part only stores lines in another file that contains 'a' not 'A'.

Similar questions