Q. A file contains a list of telephone numbers in the following form:

Arvind 7258031
Sachin 7259197

The names contain only one word the names and telephone numbers are separated by white spaces Write program to read a file and display its contents in two columns.


You can understand by Watching video :-



Answer :-

print("Name\t|\tPhone no. ")

file = open("Path Walla.txt", "r")
lst = file.readlines()

for i in lst :
    data = i.split()
    print( data[0] ,end = "\t" )
    print("|" , end = "\t")
    print ( data[1] )

file.close()

Path Walla.txt Contains :-

Arvind 7258031
Sachin 7259197
Path 256445
Walla 799645
Portal 6566363
Express 534553

Output :-

Name      |    Phone no.
Arvind    |    7258031
Sachin    |    7259197
Path        |    256445
Walla      |    799645
Portal     |    6566363
Express  |    534553

>>>


1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post