Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 我怎样才能避免;ValueError:以10为基数的int()的文本无效:''&引用;?_Python_Int_Literals_Base_Valueerror - Fatal编程技术网

Python 我怎样才能避免;ValueError:以10为基数的int()的文本无效:''&引用;?

Python 我怎样才能避免;ValueError:以10为基数的int()的文本无效:''&引用;?,python,int,literals,base,valueerror,Python,Int,Literals,Base,Valueerror,我一直在开发一个程序,该程序旨在加密用户输入的消息。加密过程完成后,我希望程序提示用户选择是否要加密另一条消息 option2 = int(input('Would you like to encrypt another message? (Yes = 1 and No = 2)')) while option2 not in [1, 2]: print 'Please type 1 or 2.' option2 = int(raw_input(

我一直在开发一个程序,该程序旨在加密用户输入的消息。加密过程完成后,我希望程序提示用户选择是否要加密另一条消息

    option2 = int(input('Would you like to encrypt another message? (Yes = 1 and No = 2)'))
    while option2 not in [1, 2]:

        print 'Please type 1 or 2.'
        option2 = int(raw_input())
    while True:
        option2 = int(raw_input())
        if option2 == 1:
            option1 = int(input('Which encryption method would you like to use? 1 = Across (NOPQ ...) and 2 = Backwards (ZYXW ...)'))
    while True:
        option2 = int(raw_input())
        if option2 == 2:
            break
此代码导致

ValueError:基数为10的int()的文本无效:“”


一个我以前从未遇到过的错误。如何解决此问题?

问题在于,您正在尝试将第一行中的内容转换为int,但您需要:

int(input(...
将输入存储在字符串中,检查

 option2 not in ['1', '2']
这一部分应该有效


请考虑查看此处的答案,了解如何改进菜单的提示:

这意味着用户没有键入任何内容。如果您确保用户键入某些内容,它将工作。您还可以使用与