Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import string
  2.  
  3. import sys
  4.  
  5. key = input()
  6.  
  7. try:
  8.     key = int(key)
  9. except ValueError as e:
  10.     print("INVALID INPUT")
  11.     sys.exit()
  12.  
  13. input_string = input()
  14.  
  15. alphabet = list(string.ascii_uppercase)
  16. input_string = input_string.upper()
  17. input_string = list(input_string)
  18. output_string = []
  19.  
  20. for char in input_string:
  21.  
  22.     if char in alphabet:
  23.         alphabet_index = alphabet.index(char)
  24.         new_index = key + alphabet_index
  25.  
  26.         if new_index > 25:
  27.             new_index = 0 + (new_index - 26)
  28.  
  29.         output_string.append(alphabet[new_index])
  30.     else:
  31.         output_string.append(char)
  32.  
  33.  
  34. print(''.join(output_string))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement