title: Python 3.6 - How to translate a telephone number with words
body: <p>Trying to get this program to translate letters into numbers so a telephone number with words can be input and will output the number version. (1800GOTJUNK = 18004685865) Not sure where Im going wrong but every output just gives whatever the last letter is and repeats its number for all numbers (1800adgjmptw = 18009999999). Any help would be greatly appreciated, thanks.</p>
  
  <pre><code>def transNum(string):
      number = 1
      for ch in string:
          if ch.lower() in "abc":
              number = 2
          elif ch.lower() in "def":
              number = 3
          elif ch.lower() in "ghi":
              number = 4
          elif ch.lower() in "jkl":
              number = 5
          elif ch.lower() in "mno":
              number = 6
          elif ch.lower() in "pqrs":
              number = 7
          elif ch.lower() in "tuv":
              number = 8
          elif ch.lower() in "wxyz":
              number = 9
      return number
  
  
  def translate(phone):
      newNum = ""
      for ch in phone:
          if ch in   ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]:
              newNum = newNum + str(transNum(phone))
          else:
              newNum = newNum + ch
      return newNum
  
  def main():
      phone = input("enter a phone number")
      noLetters = translate(phone)
      print("The number you entered: ", phone)
      print("Translates to: ", noLetters)
  
  main()
  </code></pre>