0

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()
Luxe
  • 69
  • 1
  • 6

1 Answers1

0

convert userinput as int

userinput = int(input("Enter your choice: "))

or

if userinput=='1':
elif userinput=='2':

convert this

sourab maity
  • 1,025
  • 2
  • 8
  • 16
  • 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 – Luxe Nov 28 '20 at 04:15
  • @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. – Gino Mempin Nov 28 '20 at 04:42
  • oh sorry, will post a new one – Luxe Nov 28 '20 at 04:49