Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python 3.4.3:解释Python输入?_Python 3.x - Fatal编程技术网

Python 3.x Python 3.4.3:解释Python输入?

Python 3.x Python 3.4.3:解释Python输入?,python-3.x,Python 3.x,到目前为止,我已经开始编写这段代码,现在我迷路了。我有一个无头程序,可以将键入的任何内容转换为utf-16,然后解码utf-16。我希望它支持许多其他加密类型,并最终添加一个非常简单的gui。 我的问题是: x = True while x is True: print(''' You can type help, decode, info, encode. or quit in the Command Line.''') mInput = input('Command Lin

到目前为止,我已经开始编写这段代码,现在我迷路了。我有一个无头程序,可以将键入的任何内容转换为utf-16,然后解码utf-16。我希望它支持许多其他加密类型,并最终添加一个非常简单的gui。 我的问题是:

x = True
while x is True:
    print('''     You can type help, decode, info,  encode. or quit in the Command Line.''')
mInput = input('Command Line:')
if mInput == 'encode':
        #  print("     Write base utf or rot to be decrypted and then write the last number like base 32 or utf-16)
        iN = input("encode:")
        nC = iN.encode('utf-16')
        print(nC)
if mInput == 'decode':
        dC = input('decode:')
        dC = iN.decode('utf-16')
        print(dC)
if mInput == 'help':
            pass       
if mInput == 'info':
    print("This encodes anything you type in into your choice of encryption", '\n',
          "Or you can choose decode and will decode anything you type"
          "into english,")
if mInput == "quit":
    quit()
if mInput != 'decode' or 'encode' or 'help' or 'info':
    print(mInput, "is not a supported input please try again")
当我运行这个程序时,它会进行编码和解码,但它总是说我写的东西不受支持:

`if mInput != 'decode' or 'encode' or 'help' or 'info':
    print(mInput, "is not a supported input please try again")`

它总是说,在我输入我想要的编码后,不支持ID。我如何解决这个问题并以更pythonically的方式编写这个程序(lol:)

因为您不使用
elif
,它将运行if语句,即使它已成功输入一个,因此它将始终运行您在那里的最后一个语句

最后一条语句检查的是,您输入的内容是否不等于您检查的字符串中的至少一个。您要做的是检查输入是否不等于字符串的所有值。所以你会想要:

x = True
while x is True:
    print('''     You can type help, decode, info,  encode. or quit in the Command Line.''')
    mInput = input('Command Line:')
    if mInput == 'encode':
        #  print("     Write base utf or rot to be decrypted and then write the last number like base 32 or utf-16)
        iN = input("encode:")
        nC = iN.encode('utf-16')
        print(nC)
    elif mInput == 'decode':
        dC = input('decode:')
        dC = dC.decode('utf-16')
        print(dC)
    elif mInput == 'help':
            pass       
    elif mInput == 'info':
        print("This encodes anything you type in into your choice of encryption", '\n',
        "Or you can choose decode and will decode anything you type"
        "into english,")
    elif mInput == "quit":
        quit()
    else:
        print(mInput, "is not a supported input please try again")

如果您不使用If、elif、else语句,您可能希望将上一个语句中的“or”改为“and”

非常感谢,但当我运行此程序时,我一直收到一个错误?否则会出错!='“解码”和“编码”以及“帮助”和“信息”:“^SyntaxError:无效的语法愚蠢的错误,请在您的行中再次查看以上答案
如果输入错误!=”“解码”或“编码”或“帮助”或“信息”不起作用,您希望它做什么!它的解释如下:
if mInput!='解码'或真或真或真:
。您需要的是:
如果mInput不在{“decode”、“encode”、“help”、“info”中: