I have a problem with showing my eight character key to the user, I want the program to only show the last row, however I don't know how.
The output looks like this:
This program has three choices.
Encrypt a message.
Decrypt the message.
Exit the program.
Make your choice: 1
This text below will be encrypted:
Somewhere in la Mancha, in a place whose name I do not care to remember, a gentleman lived not long ago, one of those who has a lance and ancient shield on a shelf and keeps a skinny nag and a greyhound for racing.
This is your eight character key.
['H']
The last row is your eight character key.
['H', 'D']
This is your eight character key.
['H', 'D', 'z']
This is your eight character key.
['H', 'D', 'z', '#']
The last row is your eight character key.
['H', 'D', 'z', '#', "'"]
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y']
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y', 'i']
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y', 'i', '1']
All I want for this program is to print the last line of the eight character key.I wouldn't mind if you guys change the output. Keep in mind that the code that you need to look at is in the procedure called 'EncryptCode' My code looks like this:
import random
with open ("E:\Controlled Assessment CS\Controlled Assessment Sample.txt",mode="r",encoding="utf=8") as encrypt_file:
encrypt = encrypt_file.read()
def EncryptCode():
print ("This text below will be encrypted:")
printMessage(encrypt)
eightNumKey = 0
ASCIINumber = []
ASCIIKey = []
while eightNumKey !=8:
eightNumKey = eightNumKey + 1
RandomNumber = random.randint(33,126)
ASCIINumber.append(RandomNumber)
RandomCharacter = chr(RandomNumber)
ASCIIKey.append(RandomCharacter)
print ("This is your eight character key. \n",ASCIIKey)
def showMenu():
choice = input("\n\nMake your choice: ")
if choice == "1":
EncryptCode()
showMenu()
elif choice == "2":
DecryptCode()
showMenu()
elif choice not in ["1","2","3"]:
print(choice,"Is not one of the choices")
showMenu()
print("This program has three choices.")
print("\n1. Encrypt a message.")
print("\n2. Decrypt the message.")
print("\n3. Exit the program.")
showMenu()