Discover answers to your questions with Westonci.ca, the leading Q&A platform that connects you with knowledgeable experts. Ask your questions and receive detailed answers from professionals with extensive experience in various fields. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

Alphabetic Telephone Number Translator
Hi, I've got an assignment due tonight (this is Python). I thought I was finished, but after looking over the directions that I didn't read carefully the first time, I'm now realizing that I've made a mistake.
This is what I have:
Directions:
Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. Should define a function to convert a character to digit number. 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.
The program runs fine and does what the directions have asked, however, I did not define a function to convert characters to digit numbers. Can somebody assist me in making a function out of what I have so far? It would be greatly appreciated, thank you.
Code:
user_number = input("Enter the telephone number" \
"in the format XXX-XXX-XXXX like 123-FOO-BAAR: ").upper()
phone_number = ""
for DIGIT in user_number:
if(DIGIT.isalpha()):
if (DIGIT in "ABC"):
phone_number += "2"
elif (DIGIT in "DEF"):
phone_number += "3"
elif (DIGIT in "GHI"):
phone_number += "4"
elif (DIGIT in "JKL"):
phone_number += "5"
elif (DIGIT in "MNO"):
phone_number += "6"
elif (DIGIT in "PQRS"):
phone_number += "7"
elif (DIGIT in "TUV"):
phone_number += "8"
elif(DIGIT in "WXYZ"):
phone_number += "9"
else:
phone_number += DIGIT


print("The phone number is", phone_number)