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

Write a complete Python program, including appropriate comments, that prints a t

ID: 3760628 • Letter: W

Question

Write a complete Python program, including appropriate comments, that prints a telephone number
such as 555-GET-FOOD with only numeric digits.

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, C: 2
D, E, F: 3
G, H, I: 4
J, K, L: 5
M, N, O: 6
P, Q, R, S: 7
T, U, V: 8
W, X, Y, Z: 9


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.

Sample Output 1:
Enter a phone number to be translated:
800-GET-FOOD
800-438-3663


Sample Output 2:
Enter a phone number to be translated:
800-THE-BEST
800-843-2378

Explanation / Answer

def toPhoneNumber(str):
   str=str.replace("A", "2")
   str=str.replace("b", "2")
   str=str.replace("C", "2")
  
   str=str.replace("D", "3")
   str=str.replace("E", "3")
   str=str.replace("F", "3")
  
   str=str.replace("G", "4")
   str=str.replace("H", "4")
   str=str.replace("I", "4")
  
   str=str.replace("J", "5")
   str=str.replace("K", "5")
   str=str.replace("L", "5")
  
   str=str.replace("M", "6")
   str=str.replace("N", "6")
   str=str.replace("O", "6")
  
   str=str.replace("P", "7")
   str=str.replace("Q", "7")
   str=str.replace("R", "7")
   str=str.replace("S", "7")
  
   str=str.replace("T", "8")
   str=str.replace("U", "8")
   str=str.replace("V", "8")
  
   str=str.replace("W", "9")
   str=str.replace("X", "9")
   str=str.replace("Y", "9")
   str=str.replace("Z", "9")

   return str
  
str=input("Enter a phone number to be translated: ")
print(toPhoneNumber(str))

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