Question

In: Computer Science

This task is solved in Python 3. Develop a program that can change the phone number...

This task is solved in Python 3.

Develop a program that can change the phone number of a person in phone.txt (hint: the easiest thing is probably to make a new version of the file, and then delete the old one before the new is renamed to phone.txt)

Name: John

Old phone number: 99776612

New number: 99889999

>>>

phone.txt

Replaced by ------>

phone.txt

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99776612

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99889999

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

Solutions

Expert Solution

# Python Code

# read phone.txt
try:
    file = open("phone.txt", 'r')
    phone_book = []
    for i in file:
        line = i.rstrip().split(" ")
        phone_book.append(line)
    # close the file
    file.close()
    # delete file
    del(file)
    name = input("Name: ")
    old_phone_number =input("Old phone number: ")
    new_number = input("New Number: ")
    # open file writing mode
    file1 = open("phone.txt", 'w')
    # search number in the list
    for i in phone_book:
        if i[1] == old_phone_number:
            i[1] = new_number
        # now write the complete data to phone.txt
        file1.write(i[0]+" "+i[1]+"\n")
    # close the file
    file1.close()


except FileNotFoundError:
    print("File not found")

# file

# Output

//If you need any help regarding this solution... please leave a comment. thanks


Related Solutions

This task is solved in Python 3. Develop a program that can, among other things, manage...
This task is solved in Python 3. Develop a program that can, among other things, manage your courses and course results. It must also be able to calculate the average grade, for all grades or for a selection of grades limited to a certain subject area and / or course level (100, 200 or 300 level). NB! All courses are worth the same amount of credits. The program should have two global collections Courses is a list that contains the...
This task is solved in Python 3. Develop a function which counts the number of vowels...
This task is solved in Python 3. Develop a function which counts the number of vowels in a text. >>> numberofVowels ("There is a cat outside the house") 13
This task is solved in Python 3. Develop a program that lets the user add new...
This task is solved in Python 3. Develop a program that lets the user add new people to the file phone.txt Add name and number, end with <enter> Name and number: Robin 94567402 Name and number: Jessica 99468283 Name and number: >>> Phone.txt Expanded to ------> Phone.txt Mary 98654321 June 99776655 Chris 99112233 Viv 98554455 John 99776612 Joe 97888776 Rick 99455443 Susan 98122134 Jill 99655732 Bob 98787896 Mary 98654321 June 99776655 Chris 99112233 Viv 98554455 John 99776612 Joe 97888776 Rick...
MUST BE PYTHON 3 Instructions: The following programming problem can be solved by a program that...
MUST BE PYTHON 3 Instructions: The following programming problem can be solved by a program that performs three basic tasks (Input Data, Process Data, Output Results) along with selection and repetition coding techniques. Problem Statement A finance company provides loans for motorcycles at different rates depending on how much the total loan amount is and how many payments will be made on the loan. Using the information in the table below, write a program that will calculate the monthly payment...
This task is about classes and objects, and is solved in Python 3. We will look...
This task is about classes and objects, and is solved in Python 3. We will look at two different ways to represent a succession of monarchs, e.g. the series of Norwegian kings from Haakon VII to Harald V, and print it out like this: King Haakon VII of Norway, accession: 1905 King Olav V of Norway, accession: 1957 King Harald V of Norway, accession: 1991 >>> Make a class Monarch with three attributes: the name of the monarch, the nation...
PYTHON Exercise 3. Phone Number and Email Address Extractor Say you have the boring task of...
PYTHON Exercise 3. Phone Number and Email Address Extractor Say you have the boring task of finding every phone number and email address in a long web page or document. If you manually scroll through the page, you might end up searching for a long time. But if you had a program that could search the text in your clipboard for phone numbers and email addresses, you could simply press ctrl-A to select all the text, press ctrl-C to copy...
IN PYTHON Develop a program in python that includes a number of functions for the multi-server...
IN PYTHON Develop a program in python that includes a number of functions for the multi-server queue. The program accepts arrival and services rates and the number of servers and calls your functions to output the average number of customers and average waiting time in the system.
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...
First, the Python program prompts user to enter user information (name, email, and phone number). Then...
First, the Python program prompts user to enter user information (name, email, and phone number). Then it displays a menu called “Fish Information” that has the following fish type: 1. Cat Fish 2. Red Fish 3. Any other fish Let user choose the fish type that he/she got and input the length of the fish. Then the program will determine what should be done with this particular fish. Based on the following criteria: Criteria: Length: FISHTYPE - Cat Fish <10:...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT