Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
  2. Type "copyright", "credits" or "license()" for more information.
  3. >>> ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
  4.  
  5. def Menu():
  6. print("Please choose from the following: \n")
  7. print("'e' to encode a string.")
  8. print("'d' to decode a string.")
  9. print("'q' to quit.\n")
  10. choice = input("Please enter one of the letters above.\n")
  11. if choice == "e":
  12. Encode()
  13. if choice == "d":
  14. Decode()
  15. if choice == "q":
  16. print("The program will now exit.")
  17. quit()
  18.  
  19. def stringValidation():
  20. while True:
  21. try:
  22. valid = str(input("Enter a string to encode.\n"))
  23. return valid
  24. break
  25. except:
  26. print("Value Error. Enter a string with only letters from the alphabet.")
  27. continue
  28.  
  29. def shiftValidation():
  30. while True:
  31. try:
  32. valid = int(input("Enter the number of shifts you would like.\n"))
  33. return valid
  34. break
  35. except:
  36. print("Value Error. Please enter an integer.")
  37.  
  38. def shiftValidation2():
  39. while True:
  40. try:
  41. valid = int(input("Enter the number of shifts you would like.\n"))
  42. return valid
  43. break
  44. except:
  45. print("Value Error. Please enter an integer.")
  46.  
  47. def Encode(shift):
  48. data = []
  49. string = stringValidation()
  50. shift = shiftValidation()
  51. for i in string:
  52. if i.strip() and i in ALPHABET:
  53. data.append(ALPHABET[(ALPHABET.index(i) + shift) % 26])
  54. else:
  55. data.append(i)
  56. output = ''.join(data)
  57. return output
  58.  
  59. def Decode():
  60. print("Hello.")
  61.  
  62.  
  63. Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement