我在if/else语句中的语法有什么问题?

0 python syntax-error python-2.7

我试图在Python 2.7上编写一个简单的加密程序时遇到了极其令人沮丧的错误.基本上它通过说我的语法无效而拒绝if/else语句,我不知道我做错了什么.:在if输入=="1":语句中,Python突出显示为不正确.

    #Main menu function, directs user to an operation
    def menu():
        input = raw_input("Type 1 for encryption, 2 for decryption, or 3 for information."
        if input == "1":
            print "Encryption selected..."
            encrypt()
        elif input == "2":
            print "Decryption selected..."
            decrypt()
        elif input == "3":
            print "Loading info..."
            info()
        else:
            print "ERROR: INVALID INPUT"
            menu()
Run Code Online (Sandbox Code Playgroud)

Dul*_*lax 5

你错过了raw_input()一行的结尾括号吗?

更改

input = raw_input("Type 1 for encryption, 2 for decryption, or 3 for information."
Run Code Online (Sandbox Code Playgroud)

input = raw_input("Type 1 for encryption, 2 for decryption, or 3 for information.")
Run Code Online (Sandbox Code Playgroud)

  • 天哪,这很尴尬. (2认同)