I'm doing an assignment for class, where we're supposed to:
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. Use a loop to iterate over each character in the string. Write a function that converts a letter to the correct number according to the mapping listed above. Call this function in the loop to convert the characters.
This is the code I have so far:
# write function that converts letter to number
def num_trans(number):
num = number.upper()
if char == "A" or char == "B" or char == "C":
num.replace(char,"2")
elif char == "D" or char == "E" or char == "F":
num.replace(char,"3")
elif char == "G" or char == "H" or char == "I":
num.replace(char,"4")
elif char == "J" or char == "K" or char == "L":
num.replace(char,"5")
elif char == "M" or char == "N" or char == "O":
num.replace(char,"6")
elif char == "P" or char == "Q" or char == "R" or char == "S":
num.replace(char,"7")
elif char == "T" or char == "U" or char == "V":
num.replace(char,"8")
elif char == "W" or char == "X" or char == "Y" or char == "Z":
num.replace(char,"9")
# ask for user input phone number
numb = input("Please input a number in the format XXX-XXX-XXXX: ")
# change letters to numbers
# use loop to go over each character
for char in numb:
new_num = num_trans(numb)
# print number
print(new_num)
Anything I enter in the input, I just get "None". I have no idea how to fix this. Please help