In: Computer Science
(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.
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()