Inactive Tutor answered 04/18/20
William Jeffrey P.
asked 04/11/19Hi, I need help with a program I am working on. This is the question?
How would I write a Python program that inputs a string of characters which represent a vanity telephone number, e.g., 800-MYPYTHON, and prints the all numeric equivalent, 800-69798466. You should implement this using a loop construct to process each character from left to right. Build a new string that is the all numeric equivalent and then print the string.
Follow
1
Add comment
More
Report
1 Expert Answer
Tutor
New to Wyzant
phoneNumber = "800-MYPYTHON"
newNumber = ""
for char in phoneNumber:
if(char == "A" or char == "B" or char == "C"):
newNumber += "2"
elif(char == "D" or char == "E" or char == "F"):
newNumber += "3"
elif(char == "G" or char == "H" or char == "I"):
newNumber += "4"
elif(char == "J" or char == "K" or char == "L"):
newNumber += "5"
elif(char == "M" or char == "N" or char == "O"):
newNumber += "6"
elif(char == "P" or char == "Q" or char == "R" or char == "S"):
newNumber += "7"
elif(char == "T" or char == "U" or char == "V"):
newNumber += "8"
elif(char == "W" or char == "X" or char == "Y" or char == "Z"):
newNumber += "9"
else:
newNumber += char
print(newNumber)
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.