Q. Write a program to edit the phone number of “Arvind” infile “phonebook.det”. If there is no record for “Arvind”, report error.


Answer =

 

Try = 0
f = open("phonebook.det","r")
data = f.readlines()
f.close()
f = open("phonebook.det","w")
name = input("Enter name which you want search :-")
for i in range(len(data)) :
    line = data[ i ] . split()
    if line[0] == name :
        phone = input("Enter new Phone :-")
        data[ i ] =  name + " " + phone
        Try = 1
if Try != 1 :
        print("Try again !!!!! ")

for i in range(len(data)) :
    line = data[ i ] . split()
    for j in line :
        f.write( j + "\t")
    f.write("\n")

f.close()
print("Thankyou")


Post a Comment

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

Previous Post Next Post