For some dumb reason, I can't get my if..elif to print in python 3 but it somehow works in python 2. I'm not sure what I missed.
This is my if, elif
def encdec(userinput, machine, plaintext):
if userinput == 1:
print("-----------------------------------")
print("Encoded:")
enc = machine.encrypt(plaintext)
print(enc)
elif userinput == 2:
print("-----------------------------------")
print("Decoded:")
dec = machine.decrypt(plaintext)
print(dec)
This is my main using python 3's input function.
class main():
print("Cryptography")
print("[1] Encode")
print("[2] Decode")
userinput = input("Enter your choice: ")
plaintext = input("Plaintext: ")
rightkey = "SGLBIZHJMFTRXAVKNQPDWYCUOE"
leftkey = "XLEMFHIWOVNYRUDQCJPASGBTKZ"
if rightkey.isupper()==True:
rightkey = rightkey.lower()
if plaintext.isalnum()==True:
import re
plaintext = re.sub("[^a-zA-Z]+","",plaintext)
cm = SaveSpaces(UpperCase(CryptMachine(Chao(), leftkey)))
cm.set_alphabet(rightkey)
encdec(userinput, cm, plaintext)
if __name__ == "__main__":
main()
convert userinput as int
userinput = int(input("Enter your choice: "))
or
if userinput=='1':
elif userinput=='2':
convert this
thank you, it worked! but can I ask also why my decode function has an error: TypeError: can only concatenate str (not "bytes") to str
@Hope Less If you have follow-up or more questions, then post a new question for each one. Each Q&A pair should focus on a specific problem, not make it a discussion for the entire code.
oh sorry, will post a new one