Question

In: Computer Science

Alphabetic Telephone Number Translator           Many companies use telephone numbers like 555-GET-FOOD so the number is...

Alphabetic Telephone Number Translator

          Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion:

A, B, and C = 2

            D, E, and F = 3

            G, H, and I = 4

            J, K, and L = 5

            M, N, and O = 6

            P, Q, R, and S = 7

            T, U, and V = 8

            W, X, Y, and Z = 9

For your program, you will be using a secret code as show below:

A and C = 2

            D and E = 3

            B, G, H, and I = 4

            J, K, L, and X = 5

            F, M, N, O, and P = 6

            Q = 7

            R, S, T, U, and V = 8

            X, Y, and Z = 9

            Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX (where X can be an upper- or lower-case letter or a number).

  • The program 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-GOOD the application should display 555-438-4663.
  • Your program should have good internal documentation, use methods and be user friendly.
  • Make sure that when the user runs the program, they understand how to enter the telephone number – be extremely user friendly.

Solutions

Expert Solution

Python Program:

""" Python Program that translates Phone number into Numerical Format """

def getCharacter(ch):
   # Checking character for corresponding alphabet
   if ch in "ABC":
       return '2'
   elif ch in "DEF":
       return '3'
   elif ch in "GHI":
       return '4'
   elif ch in "JKL":
       return '5'
   elif ch in "MNO":
       return '6'
   elif ch in "PQRS":
       return '7'
   elif ch in "TUV":
       return '8'
   elif ch in "WXYZ":
       return '9'
   else:
       return ch

def getInput():
""" Reads input from user """
# Reading phone number from user
phoneNum = input("Enter the number in the format of XXX-XXX-XXXX: ")
return phoneNum.upper()
  
def main():
""" Main function """
# Reading phone number from user
phoneNum = getInput()
new_phone_num = ""
# Iterating over each character
for ch in phoneNum:
# Checking character for corresponding alphabet
new_phone_num += getCharacter(ch)
# Printing new phone number
print(new_phone_num)
  
# Calling main function
main()

Code Screenshot:

Sample Run:


Related Solutions

To make telephone numbers easier to remember, some companies use letters to show their telephone number....
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Instructions Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone...
In PYTHON On a standard telephone, alphabetic letters are mapped to numbers in the following fashion:...
In PYTHON On a standard telephone, alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, and R = 7 T, U, and V = 8 W, X, Y, and Z = 9 Write a fruitful function that takes any string of alphanumeric characters and returns a string...
write an application that inputs a telephone number as a stringin the form (555) 555_5555....
write an application that inputs a telephone number as a string in the form (555) 555_5555. the application should use string method split to extract the area code as a token. the first three digits of the phone number as a token and the last four digits of the phone number as a token. the seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be printed. Remember that...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the form (555) 555-5555. The program should use function strtok to extract the area code as a token, the first three digits of the telephone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The program should convert the area-code string to int and convert...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be...
How many​ 7-digit telephone numbers are possible if the first digit cannot be eight and ​(a)...
How many​ 7-digit telephone numbers are possible if the first digit cannot be eight and ​(a) only even digits may be​ used? ​(b) the number must be a multiple of 10​ (that is, it must end in​ 0)? ​(c) the number must be a multiple of 1,000? ​(d) the first 2 digits are 92? ​(e) no repetitions are​ allowed?
Define food security. If gumans produce enough food for everyone, why are so many people food...
Define food security. If gumans produce enough food for everyone, why are so many people food unsecure? (Subject: Environmental Biology)
Java assignment Get a file name fname for output • Get number of data (numbers) (N)...
Java assignment Get a file name fname for output • Get number of data (numbers) (N) you want to process from the user • Get N numbers from the users through keyboard and store them in an array • Write the numbers into the file fname
how to code in c# to get the total number of 1's as the numbers are...
how to code in c# to get the total number of 1's as the numbers are added in a Listbox in windows forms
many people still do not get their economic and social rights, such as rights to food,...
many people still do not get their economic and social rights, such as rights to food, education, or housing. Find a case where there is one of the following: persistent hunger (or malnutrition), homelessness, or denial of education, and outline why this occurs, and why the situation is a violation of human rights?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT