此程序允许用户输入一个电话号码,然后输出电话号码。例如,他们输入1-800-flowers等字母,然后输出1-800-3569377。
目前我遇到的问题是:每当我输入电话号码时,我都不会收到任何类型的输出。
想法?
#This program will be used to convert a telephone number with letters in it to numbers.
def getNumber(uppercaseLetter):
if uppercaseLetter == 'A' or uppercaseLetter == 'a' or uppercaseLetter == 'B' or uppercaseLetter == 'b' or uppercaseLetter == 'C' or uppercaseLetter == 'c':
return(2)
elif uppercaseLetter == 'D' or uppercaseLetter == 'd' or uppercaseLetter == 'E' or uppercaseLetter == 'e' or uppercaseLetter == 'F' or uppercaseLetter == 'f':
return(3)
elif uppercaseLetter == 'G' or uppercaseLetter == 'g' or uppercaseLetter == 'H' or uppercaseLetter == 'h' or uppercaseLetter == 'I' or uppercaseLetter == 'i':
return(4)
elif uppercaseLetter == 'J' or uppercaseLetter == 'j' or uppercaseLetter == 'K' or uppercaseLetter == 'k' or uppercaseLetter == 'L' or uppercaseLetter == 'l':
return(5)
elif uppercaseLetter == 'M' or uppercaseLetter == 'm' or uppercaseLetter == 'N' or uppercaseLetter == 'n' or uppercaseLetter == 'O' or uppercaseLetter == 'o':
return(6)
elif uppercaseLetter == 'P' or uppercaseLetter == 'p' or uppercaseLetter == 'Q' or uppercaseLetter == 'q' or uppercaseLetter == 'R' or uppercaseLetter == 'r' or uppercaseLetter == 'S' or uppercaseLetter == 's':
return(7)
elif uppercaseLetter == 'T' or uppercaseLetter == 't' or uppercaseLetter == 'U' or uppercaseLetter == 'u' or uppercaseLetter == 'V' or uppercaseLetter == 'v':
return(8)
elif uppercaseLetter == 'W' or uppercaseLetter == 'w' or uppercaseLetter == 'X' or uppercaseLetter == 'x' or uppercaseLetter == 'Y' or uppercaseLetter == 'y' or uppercaseLetter == 'Z' or uppercaseLetter == 'z':
return(9)
def numberTranslate():
phoneNumber = str(input("Please enter a phone number to be converted: "))
for ch in phoneNumber:
if ch in ['A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','Q','q','R','r','S','s','T','t','U','u','V','v','W','w','X','x','Y','y','Z','z']:
result = getNumber(ch)
return result
else:
return ch
print(phoneNumber)
numberTranslate()