title: Python shift with alphabet
body: <pre><code>def menu():
      choice = input("Press 1 to encode, 2 to decode, 9 to exit ")
      return choice
  
  def makeKeycode(message):
      key = input("What is the key? ").upper()
      length = len(message)
      keycode = ""
      counter = 0
      while length &gt;0:
          if counter == len(key):
              counter = 0
          keycode = keycode + key[counter]
          counter = counter + 1
          length = length - 1
      print(keycode)
      return keycode
  
  def enterMessage():
      message = input("What is the message ").upper()
      return message
  
  def encodeMessage(message, keycode):
      ciphertext =""
      alphabet= "ABCDEFGHIJKLMNOPQRTUVWXYZ"
      for i in range (len(message)):
          character = message[i]
          charCode = alphabet.find(character)
          keycodeChar =keycode[i]
          keyLetter = alphabet.find(keycodeChar)
          position = (charCode + keyLetter)%25
          cipherLetter = alphabet[position]
          ciphertext =ciphertext + cipherLetter
      return ciphertext
  
  def decodeMessage(ciphertext,keycode):
      ciphertext =""
      alphabet= "ABCDEFGHIJKLMNOPQRTUVWXYZ"
      for i in range (len(ciphertext)):
          character = ciphertext[i]
          charCode = alphabet.find(character)
          keycodeChar =keycode[i]
          keyLetter = alphabet.find(keycodeChar)
          position = (charCode - keyLetter)%25
          cipherLetter = alphabet[position]
          ciphertext =ciphertext - cipherLetter
      return message
  
  def enterCipher ():
      ciphertext = input("Enter the text to be decoded")
      return ciphertext
  
  def encode():
      message = enterMessage()
      keycode = makeKeycode(message)
      ciphertext = encodeMessage(message,keycode)
      print(ciphertext)
  def decode():
  
      keycode = makeKeycode(ciphertext)
      message = decodeMessage(ciphertext, keycode)
      print (message)   
  
  def main():
      MyDictionary=("A:1","B:2","C:3","D:4","E:5","F:6","G:7","H:8","I:9","J:10","K:11","L:12","M:13","N:14","O:15","P:16","Q:17","R:18","S:19","T:20","U:21","V:22","W:23","X:24","Y:25","X:26")
      print (MyDictionary)
      choice = 0
      while choice !=9:
          choice = int(menu())
  
          if choice == 1:
              encode()
          elif choice == 2:
              decode()
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Hi, I cant get my code to work, my encode function works but i am struggling to fix my decode function. I dont understand where i am going wrong. I want to be able to decode the message i will have encoded, but this doesn't work as the decode function stops the program. Have I made an error in the coding? Thanks for all the help
  Regards</p>