Thursday, July 23, 2020

NETWORK AND COMMUNICATION QUIZ-1


Reverse Line by Line Printing of File content ,two different Program


Untitled18
In [1]:
#program to print line by line from end to start in reverse
def reverseprint():
    f=open('fil1.txt','r')
    l=f.readlines()
    print('number of line in File is ',len(l))
    for i in range(-1,-len(l)-1,-1):
        print(l[i])
    
In [2]:
#program to print line by line from end to start in reverse
def reverseprint1():
    f=open('fil1.txt','r')
    l=f.readlines()
    print('number of line in File is ',len(l))
    for i in range(len(l)-1,-1,-1):
        print(l[i])
In [4]:
reverseprint()  # calling function 
number of line in File is  11
hari

Hello

How

hari

Hello

How

America

srilanka

china

Paistan

india

In [5]:
reverseprint1() #calling function for 1
number of line in File is  11
hari

Hello

How

hari

Hello

How

America

srilanka

china

Paistan

india

In [ ]: