I'm trying to write a function that allows a user to update a contact's address book. I want to be able to update the first and last name as well as the mobile and home number. This is what I have so far:
def update_contact():
phonebook = open("contacts.txt", "r")
readfile = phonebook.read()
print(readfile)
contact = input("Which contact do you want to update: ")
if contact in readfile:
last = input("Enter new last name: ")
phonebook = open("contacts.txt", "a")
for line in open("contacts.txt"):
line = line.replace(contact, last)
phonebook.write(line)