Question

In: Computer Science

(Language: PYTHON) Format existing address records and eliminate records with missing critical fields.Critical fields include FirstName,...

(Language: PYTHON) Format existing address records and eliminate records with missing critical fields.Critical fields include FirstName, Lastname, Zipcode+4, and Phone number for customers. Use an array to hold data with these 4 fields containing at least 25records. The Zipcode field should contain either traditional 5-digit Zipcode(e.g. 21801)or Zip+4 format(e.g 21801-1101). The phone numbers should contain 10-digit (e.g. 5555555555)or formatted 10-digit(e.g. 555-555-5555). Some records might be corrupt so the data needs to be munged. At this point, we assume only U.S data will be present therefor country code is not needed.

Label each column, properly format the Zip code to be either 11111 or 11111-1111 formats, properly formatthe phone numbers to always be 111-111-1111 format, and replace incorrect values with a blank string.

Notice invalid data was removed and formatting was applied as required. Commas can be left if desired. Default alignment with the column labels is acceptable.

  1. Hardware the 25 records.
  2. Use comments to document your code

Solutions

Expert Solution

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================

def digit_count(phone_number):
    digits = 0
    for letter in phone_number:
        if '0' <= letter and letter <= '9':
            digits += 1
    return digits


def format_phonenumber(phone_number):
    formatted_ph_num = ''
    count = 0
    for letter in phone_number:
        if '0' <= letter and letter <= '9':
            count += 1
            formatted_ph_num += letter
            if count == 3 or count == 6:
                formatted_ph_num += '-'
    return formatted_ph_num


def main():
    phone_number = input('Enter phone number: ')
    if digit_count(phone_number) == 10:
        formatted = format_phonenumber(phone_number)
        print('Phone number:{} formatted as 10-digit is {}'.format(phone_number, formatted))
    else:
        print('Entered phone number: {} is invalid.'.format(phone_number))


main()


Related Solutions

Using Python, Regular Expressions, .map() and other functions as appropriate to format existing address records and...
Using Python, Regular Expressions, .map() and other functions as appropriate to format existing address records and eliminate records with missing critical fields.Critical fieldsincludeFirstName, Lastname, Zipcode+4, and Phone number for customers. For this exercise, create an array to hold data with these 4 fields containing at least 25records. The Zipcode field should contain either traditional 5-digit Zipcode(e.g. 21801)or Zip+4 format(e.g 21801-1101). The phone numbers should contain 10-digit (e.g. 5555555555)or formatted 10-digit(e.g. 555-555-5555). Some records might be corrupt so the data needs...
in python programming language, please include the proper identation This homework will allow you to demonstrate...
in python programming language, please include the proper identation This homework will allow you to demonstrate understanding and engagement with the following topics: graph representations object oriented programming graph processing,such as finding shortest paths and finding tree traversals Your task is to implement a Graph class. The edges in the graph are undirected, but you must implement an Edge class. In addition, you will have a Graph class, and a Node class. You can choose to implement graphs with any...
REWRITE THE FOLLOWING CODES USING FOR LOOP. PLS USE C LANGUAGE FORMAT #include <stdio.h> int main(void)...
REWRITE THE FOLLOWING CODES USING FOR LOOP. PLS USE C LANGUAGE FORMAT #include <stdio.h> int main(void) {      int count ; scanf("%d",&count);           while(count--){                printf("\--------------------------------------------\ \n"); printf("\          BBBBB               A                   \ \n"); printf("\          B    B             A A                  \ \n"); printf("\          BBBB              A   A                 \ \n"); printf("\          B    B           AAAAAAA                \ \n"); printf("\          BBBBB           A       A               \ \n"); printf("\---------------------------------------------\ \n");             }                            return 0; }
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def...
Python coding: Write code for each method listed. Input Text File Format: username|Firstname|Lastname|password|accountnumber|balance jh123|Jane|Hudson|45678910|AB45|900 ah444|Allie|Hun|ah1234|HHYZ|1500 def build_dict(): ''' Returns a dictionary created from input file where key is an existing username and value is a list of fistname, lastname, account number and balance. '''    def write_to_file(users): ''' Writes the updated user information to user list file '''
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT