Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to enter a 10 character telephone number in t

ID: 3554194 • Letter: W

Question

Write a program that asks the user to enter a 10 character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD the application should display 555-438-3663.


def main():
    #character string
    numeric_phone=" "

    #user inputs phone number
    alpha_phone = input('Enter 10-Digit phone number: ')

    digit_list = ["2", "3","4", "5", "6", "7", "8", "9", "0"]



    for ch in alpha_phone:
        if ch.isalpha():
            ch = ch is upper()

        if ch == "A" or ch=="B" or ch=="C":
            index=0
           
        if ch == "D" or ch=="E" or ch=="F":
            index=1

        if ch == "G" or ch=="H" or ch=="I":
            index=2

        if ch == "J" or ch=="K" or ch=="L":
            index=3

        if ch == "M" or ch=="N" or ch=="O":
            index=4

        if ch == "P" or ch=="Q" or ch=="R" or ch=="S":
             if ch == "T" or ch=="U" or ch=="V":
            index=6

        if ch == "W" or ch=="X" or ch=="Y" or ch=="Z":
            index=7


        ch= digit_list[index]

        numeric_phone= numberic_phone+ch

    print(numeric_phone)
#call main
main()


Explanation / Answer

Dear,


#Program to display actual telephone number

#Define a string reference tn in which the input from the user containing the alphabetic telephone number will be stored.

# Storing the input in reference string tn
tn = input('Enter Telephone Number in Alphabetic Code: ')

#Store the string referred by tn into tnu by converting all its alphabets in uppercase using the upper() method.

tnu = tn.upper()

#Copy the first four character of tnu as they are into actual_num.

actual_num = tnu[0:4]
i=4


Initialize the While loop and run the loop from the index value 4 to the last index value of tnu.
# Ierating the loop until the condition

while i<len(tnu):

#Perform comparisons, if the index value of the current character is not 7.

    if i!=7:
        if tnu[i] == 'A' or tnu[i] == 'B' or tnu[i] == 'C':
            actual_num += '2'
        else:
            if tnu[i] == 'D' or tnu[i] == 'E' or tnu[i]
                                                    == 'F':
                actual_num += '3'
            else:
                if tnu[i] == 'G' or tnu[i] == 'H' or
                                               tnu[i]=='I':                                            
                    actual_num += '4'
                else:
                    if tnu[i] == 'J' or tnu[i] == 'K' or
                                              tnu[i]== 'L':
                        actual_num += '5'
                    else:
                        if tnu[i] == 'M' or tnu[i] == 'N'
                                           or tnu[i] =='O':
                            actual_num += '6'
                        else:
                            if tnu[i] == 'P' or tnu[i] ==
                      'Q' or tnu[i] == 'R' or tnu[i] =='S':
                                actual_num += '7'
                            else:
                                if tnu[i] == 'T' or tnu[i]
                                    == 'U' or tnu[i] =='V':
                                    actual_num += '8'
                                else:
                                    if tnu[i] == 'W' or
            tnu[i] == 'X' or tnu[i] == 'Y' or tnu[i] ==
                                                       'Z':
                                        actual_num += '9'

#If the index value is 7, store the character as it is because it is

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote