File Handling 19: Name and phone number

# Given a file containing customer names and their phone numbers, 
# write a program to find the telephone number of a given customer.

# Files: Name and phone number
import sys

fname = sys.argv[1]
fs = open(fname,"r")
Flag = False

Name = input("Enter name :")
Name = Name.strip().lower()

while(True):
    line = fs.readline()
   
    if not line:
        break
   
    L = line.split(" ")
    if(L[0].strip().lower() == Name):
        Flag = True
        print("Name =", Name.capitalize())
        print("Phone number =", L[1])
        break

if(Flag==False):
    print(Name, "- Name not found in directory")
fs.close()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu