Sunday 23 August 2020

Text File Menu driven Program 2

 PROGRAM:

  



OUTPUT:

  


  
















def writ_an_f():

    fin=open("D:\\book.txt","r")

    fout=open("D:\\story.txt","w")

    s=fin.readlines()

    for j in s:

        if 'a' in j:

            fout.write(j)

    fout.close()

    fin.close()


def cnt():

    f=open("D:\\test2.txt","r")

    cont=f.read()

    print(cnt)

    v=0

    cons=0

    l_c_l=0

    u_c_l=0

    for ch in cont:

        if (ch.islower()):

            l_c_l+=1

        elif(ch.isupper()):

            u_c_l+=1

        ch=ch.lower()

        if( ch in ['a','e','i','o','u']):

            v+=1

        elif (ch in ['b','c','d','f','g',

                     'h','j','k','l','m',

                     'n','p','q','r','s',

                     't','v','w','x','y','z']):

            cons+=1

    f.close()

    print("Vowels are: ",v)

    print("consonants are : ",cons)

    print("Lower case letters are : ",l_c_l)

    print("Upper case letters are : ",u_c_l)


#Main program

while True:


    print("\n\nText files Menu driven program:")

    

    print("1. Remove all the lines that contain" )

    print(" the character `a’ in a file and write it" )

    print(" to another file\n" )  


    print("2.Read a text file and display the" )

    print(" number of vowels/ consonants/ uppercase/" )

    print(" lowercase characters in the file\n" ) 


    print("3. Exit\n")

    ch=int(input("Enter your choice : "))

    if ch==1:

        writ_an_f()        

    elif ch==2:

        cnt()

    elif ch==3:

        break

    else:

        print( " invalid choice ")