Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
- Type "copyright", "credits" or "license()" for more information.
- >>> ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
- def Menu():
- print("Please choose from the following: \n")
- print("'e' to encode a string.")
- print("'d' to decode a string.")
- print("'q' to quit.\n")
- choice = input("Please enter one of the letters above.\n")
- if choice == "e":
- Encode()
- if choice == "d":
- Decode()
- if choice == "q":
- print("The program will now exit.")
- quit()
- def stringValidation():
- while True:
- try:
- valid = str(input("Enter a string to encode.\n"))
- return valid
- break
- except:
- print("Value Error. Enter a string with only letters from the alphabet.")
- continue
- def shiftValidation():
- while True:
- try:
- valid = int(input("Enter the number of shifts you would like.\n"))
- return valid
- break
- except:
- print("Value Error. Please enter an integer.")
- def shiftValidation2():
- while True:
- try:
- valid = int(input("Enter the number of shifts you would like.\n"))
- return valid
- break
- except:
- print("Value Error. Please enter an integer.")
- def Encode(shift):
- data = []
- string = stringValidation()
- shift = shiftValidation()
- for i in string:
- if i.strip() and i in ALPHABET:
- data.append(ALPHABET[(ALPHABET.index(i) + shift) % 26])
- else:
- data.append(i)
- output = ''.join(data)
- return output
- def Decode():
- print("Hello.")
- Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement