Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Phone Number Translator

By: ChelseaMarie on Nov 23rd, 2012  |  syntax: Python  |  size: 1.10 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def main():
  2.         phoneNum = "Enter"
  3.         print "Welcome to the Phone Number Translator!"
  4.         print #LB
  5.         phoneNum = getInput(phoneNum)
  6.         phoneNum = changePhone(phoneNum)
  7.  
  8. def getInput(phoneNum):
  9.         phoneNumRaw = raw_input("Input the phone number with letters (example, 555-GET-FOOD): ")
  10.         print #LB
  11.         #Add a check to make sure it's formatted correctly
  12.         phoneNum = phoneNumRaw.upper()
  13.         #print phoneNum
  14.         return phoneNum
  15.        
  16. def changePhone(phoneNum):
  17.         print "match letter with the number in the directory"
  18.         dict = {}
  19.         dict["A"] = "2"
  20.         dict["B"] = "2"
  21.         dict["C"] = "2"
  22.         dict["D"] = "3"
  23.         dict["E"] = "3"
  24.         dict["F"] = "3"
  25.         dict["G"] = "4"
  26.         dict["H"] = "4"
  27.         dict["I"] = "4"
  28.         dict["J"] = "5"
  29.         dict["K"] = "5"
  30.         dict["L"] = "5"
  31.         dict["M"] = "6"
  32.         dict["N"] = "6"
  33.         dict["O"] = "6"
  34.         dict["P"] = "7"
  35.         dict["Q"] = "7"
  36.         dict["R"] = "7"
  37.         dict["S"] = "7"
  38.         dict["T"] = "8"
  39.         dict["U"] = "8"
  40.         dict["V"] = "8"
  41.         dict["W"] = "9"
  42.         dict["X"] = "9"
  43.         dict["Y"] = "9"
  44.         dict["Z"] = "9"
  45.  
  46.         #print dict
  47.  
  48.         for i, j in dict.iteritems():
  49.                 newNumber = phoneNum.replace(i, j)
  50.                 print "Number: ",newNumber
  51.                 #print num
  52.        
  53. main()